none
ReportViewer to open XML document formatted with CSS? RRS feed

  • Question

  • I'm new to report viewer but it looks like it can solve my problem. I just have no idea where to begin. Simply put, I have an xml document that is styled with a css which resembles your average document outline more than it resembles a traditionally structured xml database document. What I would like to do is open the xml document apply the css then display it in the report viewer. The only reason to do this is so the report viewer would give the user a familiar print preview style display and also add headers and footers that would be statically defined outside of the xml document. The following code can be used to simply open the document, and apply a style sheet, then print it in an asp page. I'm hoping I can just somehow route that through the report view somehow. Any thoughts?
    Code Snippet

    <%
    'Load XML

    set xml = Server.CreateObject("Microsoft.XMLDOM")
    xml.async = false
    xml.load(Server.MapPath("cdcatalog.xml"))

    'Load XSL
    set xsl = Server.CreateObject("Microsoft.XMLDOM")
    xsl.async = false
    xsl.load(Server.MapPath("cdcatalog.xsl"))

    'Transform file
    Response.Write(xml.transformNode(xsl))
    %>

    Zach
    Sunday, July 15, 2007 8:04 AM

All replies

  • The layout of the xml document in question is as follows:

    Code Snippet


    <root>
      <tblk>
      <sect tag="1.0">
        <text>Overview</text>
            <para>
                <tblk>
                    <snt>content of paragraph 1</snt>
                </tblk>
            </para>
            <para>
                <tblk>
                    <snt>content of paragraph 2</snt>
                </tblk>
            </para>
            <para>
                <tblk>
                    <snt>begining of paragraph 3</snt>
                        <tblk class="n">
                            <snt>list item in para 3</snt>
                            <snt>list item in para 3</snt>
                            <snt>list item in para 3</snt>
                        </tblk>
                </tblk>
            </para>
        </sect>
        <sect tag="4.0">

        <text>Purpose</text>
            <para>
                <tblk>
                    <snt>Components are:</snt>
                </tblk>
            </para>
        <tblk>
        <sect tag="4.1"><text>Component 1</text>
          <para>
            <tblk>
              <snt>description of component 1</snt>
                <tblk class="b">
                  <snt>list for component 1</snt>
                  <snt>list for component 1</snt>
                  <snt>list for component 1</snt>
                </tblk>
             </tblk>
          </para>
          <para>
            <tblk>
              <snt>description of component 2</snt>
                <tblk class="b">
                  <snt>list for component 2</snt>
                  <snt>list for component 2</snt>
                  <snt>list for component 2</snt>
                </tblk>
             </tblk>
          </para>
        </sect>
      </tblk>
    </root>



    and the css
    Code Snippet

    /*Base*/
    root
    {
        font-family: Arial;
    }
    sect
    {
        display: list-item;
        list-style-type: decimal;
        list-style-position: inside;
        font-weight: bold;
        font-size: 11px;
        line-height: 12px;
        margin: 0px 0px 10px 20px;
    }
    para
    {
        display: block;
        margin: 0px 0px 10px 0px;
    }
    tblk
    {
        display: block;
        font-weight: normal;
        font-size: 10px;
        line-height: 11px;
        margin: 0px 0px 0px 0px;
    }
    para tblk tblk
    {
        margin: 0px 0px 0px 20px;
    }
    snt
    {
        display: inline;
    }
    /*Deeper*/
    sect sect
    {
        margin-bottom: 0px;
    }
    tblk.n snt
    {
        display: list-item;
        list-style-type: decimal;
    }
    tblk.b snt
    {
        display: list-item;
        list-style-type: disc;
        list-style-position: outside;
    }


    Zach

    Sunday, July 15, 2007 8:19 AM
  • Using the following code I have managed to put the xml in the view, but it's displayed as text instead of being rendered as xml. If anyone knows how I can make it render as html I can create an xsl to transform the doc into xhtml and then just display it that way. Hope someone can help.

    Code Snippet

    'Load XML
    Dim Xml As System.Xml.XmlDocument
    Xml = New System.Xml.XmlDocument
    Xml.Load(Server.MapPath("../App_Code/Doc.xml"))
           
    ' Set the path of the rdlc document
    rptViewer.LocalReport.ReportPath ="Reports/Doc.rdlc"

    'Set the parameters
    Dim rptParam(0) As ReportParameter
    rptParam(0) = New ReportParameter("XML", Xml.InnerXml)
    rptViewer.LocalReport.SetParameters(rptParam)

    rptViewer.LocalReport.Refresh()


    Zach
    Sunday, July 15, 2007 3:38 PM
  • First, your document is not being "styled with CSS" . It's being transformed with XSLT -- although some of the output of the XSLT happens to be CSS <s>.

     

    Second, there isn't any way in the current edition of RS to tell the default HTML renderer to "leave my tags alone" for a specific textbox or whatever .  There is also no definite word on whether something like this might be added to the Katmai version.  You might be able to add a custom report item that would do it, even in the current edition .  Sort of.

     

    But first, understand that there are good reasons, using your example, why this doesn't work exactly as you want it to.  You want to use the reportviewer's familiar "frame" but that frame includes navigation of pages, etc.  The rendering engine can't paginate if it has no idea what content you're providing as "raw HTML".  I hope you can see this...

     

    You can attach your cdcatalog as a datasource to the report.  Not the XML file, the original datasource from which you got your cdcatalog.xml file.  Or, if this is impossible, I can show you how to write a transform that will move your XML into dataset format so that you can attach the XML file as a datasource to the report.  Then you can design the report to do your HTML formatting and host it in the viewer.

    Note that you can also get XML output from the engine and attach an XSLT transform to that output -- which would be a similar transform to what you have now. Although the data would look different, it would be pretty easy to write that one.  But you would be right back where you started: now that the engine isn't doing the formatting, it can't paginate, the viewer isn't hosting the user experience, etc.

     

    >L<

    Sunday, July 15, 2007 3:56 PM
  • I don't understand what you mean by the document isn't being styled with CSS. The file that styles the xml is a css document. XSLT has things like conditionals, loops, etc, and css is just styling by tags in the document. So how is the document not being styled by css? Also, I noticed I forgot the first line of the sample xml document which is as follows:

    Code Snippet

    <?xml-stylesheet type="text/css" href="Doc.css"?>


    But back to topic... as I was doing some searching around the forum I came across some threads that said importing html into the viewer isn't possible. But there was mention of being able to use xslt transformation to make the xml document output into a styling format the viewer can understand. If this is what you were referring to when you said "[I could] also get XML output from the engine and attach an XSLT transform to that output," that would be a good plan. (I'm assuming if the xml were to be formatted and presented to the viewer in a format it can understand it would then be able to paginate the document with little issue)

    And finally, the option of importing the information into a dataset and building a report off that isn't going to be feasible however, because as I tried to show with the xml sample, the document isn't designed that way. The schema we used is as follows:

    Code Snippet

    root: Contains one tblk

    tblk: Contains any number of sect, snt

    sect: Contains one text tag and any number of para tags.

    text: contains literal string

    para: contains tblk

    snt: contains literal string


    tblk is used to group sect's so they number together. It is also used to group snt's so they can be displayed as one paragraph, a bulleted list, or numbered list. para is used to force space between objects.

    Thank you for the help thus far
    Zach
    Sunday, July 15, 2007 4:49 PM
  • Unfortunately the response I just made failed to submit. So I'll summarize hitting all the key points.

    Putting the xml into a dataset wouldn't work due to the existence of a recursive relationship in the xml document, unless datasets can deal with this now, I've never known them to handle it well.

    Would it be possible to use an xslt to transform the xml into a format the viewer can understand and therefore paginate? There isn't anything too deep involved, varying font size, bold, italic, numbered lists, bulleted lists, and indenting by section.

    What do you mean by I could get the XML output from the engine and attach an xslt transform to the output? Do you mean I could take what the viewer outputs to the page and transform it with an xslt, which would more or less make the viewer useless?

    I appreciate the help, and hope we can come to a solution to this.
    Zach
    Sunday, July 15, 2007 4:59 PM
  • Unfortunately loading a dataset isn't appropriate since the xml document has a recursive relationship that to my knowledge datasets have a hard time dealing with. Also I should note this xml file wasn't created by anything, it was made by hand to mimic the layout of a word document that outlines a security protocol. The reason for not leaving it as a word document was to make it more easily displayed on the web, and also to make it easier to parse.

    Would it be possible to create an XSLT that would transform the xml document into a format the viewer can understand and paginate?

    Also, I would like to note that the styling is indeed done with a CSS as the code snippet I provided above is purely CSS, and has not XSLT attributes to it at all. The confusion may have come about because I forgot to include the first line of the xml document which is:

    Code Snippet

    <?xml-stylesheet type="text/css" href="Doc.css"?>


    I'm sorry if this post comes off harsh, this is my third attempt at replying and the post being lost. I do appreciate the help.
    Zach
    Sunday, July 15, 2007 5:09 PM
  • sorry, seems like it just wasn't refreshing or something.
    Sunday, July 15, 2007 5:10 PM
  • >> XSLT has things like conditionals, loops, etc, and css is just styling by tags in the document.

     

    Yes, but it also has a weird default mode that doesn't have conditionals, loops, etc or even need a default template, FWIW.

     

    And you can put CSS styles in an XSLT template -- which is what I thought you were doing <s>.  Your post said:

     

    xsl.load(Server.MapPath("cdcatalog.xsl"))
    'Transform file
    Response.Write(xml.transformNode(xsl))

     

    ... right?  So I thought that is what you wanted to do... IOW, your XSLT can have a template that includes the style information as part of what it extrudes (no need for a second step or a reference to an external CSS sheet if you don't happen to want one). 

     

    This is kind of irrelevant to the main thing(s), so let's discuss.

     

     #1:

     

    >>

    And finally, the option of importing the information into a dataset and building a report off that isn't going to be feasible however, because as I tried to show with the xml sample, the document isn't designed that way. The schema we used is as follows:
    <<

     

    This is absolutely, completely 100% untrue <s>.  The fact that your schema is recursive doesn't stop you from extruding a "flat" dataset from it with the appropriate information for a report!  I do this all the time.  It's the province of XSLT to *solve* this kind of problem, actually, for partners with XML vocabularies and requirements that don't match at all. 

     

    I'll tell you what: I have no idea what your output HTML needs to look like at this point, but if you think that, given a suitable "flat" version of your contents, you can get the output you desire from a Reporting Services report, give me a sample XML input (your current XML nested structure) and a proposed dataset-shaped XML output that would provide content for a report, and I'll prove it <g>. 

     

    Or if you prefer not to do the work to figure out the appropriate dataset structure that you would need, I'll prove what I'm saying to you a different way without either of us doing any work, by showing you some examples of deeply-nested structures outputting to dataset XML.  You can contact me as lisa at spacefold dot com if you would be interested in that...

     

    #2:

     

    >>

    But there was mention of being able to use xslt transformation to make the xml document output into a styling format the viewer can understand. If this is what you were referring to when you said "[I could] also get XML output from the engine and attach an XSLT transform to that output," that would be a good plan.

    <<

     

    I think you may have misunderstood something that you read -- when you transform the XML data output by attaching an XSLT to the report (this is in Report Properties, if you want to look) you aren't getting something "the report viewer understands".  You're just getting an export format, like Excel or PDF.  It isn't known to the viewer and it isn't paginated by, or housed in, the viewer.  This really defeats your original purpose, even though it is something that can be very useful.  For example: suppose I don't like the Excel they put out in their Export format. I can take their XML and use XSLT to get the Excel I prefer.  But it's not going to appear magically in the ReportViewer.

     

    If there is mention of something different and I am not getting what you're talking about here.. .give me a reference to the thread and I'll try again.

     

    >L<

     

     

     

     

     

     


     

    Sunday, July 15, 2007 5:21 PM
  • It doesn't come off harsh.  I did already answer these questions, though <s>. Please make sure to read the answer that may appear *above* your last posts... and let me know if you want to continue discussion....

     

    >L<

    Sunday, July 15, 2007 5:26 PM