tags:

views:

317

answers:

3

I need to produce multiple HTML report files from an XML data file and I'm using C# (.NET 3.5). I essentially need on HTML report for each of certain child trees in the XML file (but they have to include some parent info).

I've decided to use XSLT, because it seems to be the most elegant solution to my problem. I can then use the .NET XslTransform.Transform method to create my HTML files... or can I?

From reading on MSDN, it seems that even in .NET 3.5 that XslTransform only supports XSLT 1.0, even though 2.0 has been around for some time. Multiple document output from a single XSLT file only became possible in XSLT 2.0.

Is there any workaround for my problem that you can think of?

A: 

Yes. Have your XSLT produce one document with "n" elements under the root. Have your code post-process those to produce "n" documents.

John Saunders
+1  A: 

I would suggest using AltovaXML to take care of this issue, that is, if you are permitted to use outside class libraries. I personally have nothing but good things to say about it. As for the code for producing multiple documents as output, your XSLT file should look something like this:

<xsl:template match="/">
<xsl:for-each select="Item">     
<xsl:variable name="filename" select="concat($solutionRoot,'\',$v1,'\',$v2,'.html')" />
<xsl:value-of select="$filename"/>
<xsl:result-document href="{$filename}" format="html-format">

   --Place document construction code here--

</xsl:result-document>
</xsl:for-each>
</xsl:template>

Essentially turn the name of the file into a variable, creating a new filename with each section of data.

Zensar
Thanks, I've seen their WYSIWYG style XSLT tool also touted on here, I'll give them a try.
cgyDeveloper
A: 

Saxon (the .net version) is the gold standard for XSLT 2 implementations. Not only is it the reference implementation for the XSLT 2.0 standard, but it is highly optimized and open source, runs as managed code (via the IKVM libraries), and supports the usual .net interfaces.

You can use the <xsl:result-document> element there without problems.

lavinio