XSL Transform Problem using Xml.XSL.Transform

  • Thread starter Thread starter John Lehmann
  • Start date Start date
J

John Lehmann

I have an interesting problem. I am performing an XSL
transform using the System.Xml.Xsl.Transform class.
I have a database that contains the XSL style sheet
string. And it seems to work pretty well for simple
transforms. But as soon as I add Xsl variables or For each
loops to the XSL string in the db, it fails to transform
the XML. I can see that it will transform everything until
that point. ALso If I copy the XSL & XML I am trying to
transform from my watch window into a file.. It works
perfectly. Any Ideas?
The following is the C# code I am using to transform & the
XSL I am using to transform.

//Code
XmlDocument transform = new XmlDocument();
transform.LoadXml(DataFormat); //DataFormat xsl string

XmlUrlResolver resolver = new XmlUrlResolver();
XslTransform xslTran = new XslTransform();
xslTran.Load(transform,resolver,null);

XmlReader reader =
xslTran.Transform(XmlData,null,resolver);
reader.MoveToContent();
string readerOutput = reader.ReadOuterXml();

//XSL
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="DataSource">
<B>Report</B><BR/>
<TABLE CELLPADDING="1" CELLSPACING="1" Border="1">
<TR><TH>Agreement Number</TH>
<TH>Name</TH>
<TH>Period</TH>
<TH>Due Date</TH>
<TH>Type</TH>
</TR>
<xsl:for-each select="tblReport
Code:
">
<TR>
<TD><xsl:value-of select="AgreementNumber"/></TD>
<TD><xsl:value-of select="Name"/></TD>
<TD><xsl:value-of select="Period"/></TD>
<TD><xsl:value-of select="DueDate"/></TD>
<TD><xsl:value-of select="Type"/></TD>
</TR>
</xsl:for-each>
<</xsl:template>
</xsl:stylesheet>
 
Can you post the XML you are using? Or at least a small subset of XML that
exhibits the problem.
also ... the XSL below - is that the XSL that works or is it the XSL that
does not work?
Can you post both versions of XSL - clearly marked?

And
what is the failure you see? You said "it fails to transform". What does
it do?
do you get an exception? What happens?

Also
what do you mean by "it works perfectly"?
What did you try, and what happens?

Finally, there is a newsgroup dedicated to XML, where you may get more eyes
looking at your problem.
microsoft.public.dotnet.xml

-Dino
 
Someone already figured out the problem on the MSDN Board
microsoft.public.dotnet.xml . I was not not properly using the Transform
method.

XmlUrlResolver resolver = new XmlUrlResolver();
XslTransform xslTran = new XslTransform();
XmlReader r = new XmlTextReader(new StringReader(DataFormat));
xslTran.Load(r,resolver,null);

StringWriter sw = new StringWriter();
xslTran.Transform(FilteredXmlRptData,null,sw,resolver);
string readerOutput = sw.ToString();
 
Back
Top