By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,396 Members | 2,501 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,396 IT Pros & Developers. It's quick & easy.

XSL Transform Problem using Xml.XSL.Transform

P: n/a
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='XYZ']">
<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>

Nov 11 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
John Lehmann wrote:
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?

That's bizarre. Most likely input XML is different that you think it is
so xsl:for-each just selects nothing. You didn't show us what XmlData is.
Also it's too expensive to build XmlDocument only to feed XslTransform -
you can rewrite transformation logic in more effective way:

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(XmlData,null,sw,resolver);
string output = sw.ToString();

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2

P: n/a
John Lehmann wrote:
The Xml Looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<DataSource>
<tblReport>
<AgreementNumber>1234567</AgreementNumber>
<Name>Martha Stuart</Name>
<Period>July 2000</Period>
<DueDate>August 15, 2000</DueDate>
<Type>Type II</Type>
</tblReport>
</DataSource>
Well, considering that XML xsl:for-each in your stylesheet really selects nothing:
<xsl:for-each select="tblReport[code='XYZ']">


because in your XML tblReport has no child Code element.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #3

P: n/a
Just changing the way to open the transform WORK! Thanx
for you input!

John
-----Original Message-----
John Lehmann wrote:
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?That's bizarre. Most likely input XML is different that

you think it isso xsl:for-each just selects nothing. You didn't show us what XmlData is.Also it's too expensive to build XmlDocument only to feed XslTransform - you can rewrite transformation logic in more effective way:
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(XmlData,null,sw,resolver);
string output = sw.ToString();

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

.

Nov 11 '05 #4

P: n/a
Just changing the way to open the transform worked.
Unfortunately since I work on sensitive data at MS, I
could not copy everything as I see it exactly (I had to
cut out a lot of things). I may have missed my select..
But like I said.. it works now.
-----Original Message-----
John Lehmann wrote:
The Xml Looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
<DataSource>
<tblReport>
<AgreementNumber>1234567</AgreementNumber>
<Name>Martha Stuart</Name>
<Period>July 2000</Period>
<DueDate>August 15, 2000</DueDate>
<Type>Type II</Type>
</tblReport>
</DataSource>
Well, considering that XML xsl:for-each in your

stylesheet really selects nothing:
<xsl:for-each select="tblReport[code='XYZ']">


because in your XML tblReport has no child Code element.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

.

Nov 11 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.