473,379 Members | 1,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

XSL Transform Problem using Xml.XSL.Transform

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
4 2935
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Xiaolei Li | last post by:
first off, i'm a total newbie at this stuff so excuse any wrong usage of terminology or whatever else. i have a XSL to transform a Document such that all "text" nodes will have a "SPAN" inserted...
2
by: John Lehmann | last post by:
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...
1
by: Brian McGuinness | last post by:
I have a question about using the STL transform algorithm in a function. What I want to do is define a group of array classes to represent APL-style arrays (arrays in which the number of...
5
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an...
3
by: Jason S | last post by:
Hello Group, I am just about tearing my hair out with this one and thought someone may have some insight. I have a transform that wasn't working so I grabbed the nearest debugger (xselerator)...
4
by: schneider | last post by:
Anyone know if there is a way to dynamicly create a Xslt template/s and use them as an xml transform with-out use files for the Xslt? All the methods I see use files. I want to create a Xslt...
6
by: tcdevelopment | last post by:
I have a XSLT file that gives expected results when I transform using MSXML V4.0 in a simple vbs file. However when using XslTransform in dotnet, I do not get the same results. The part of the...
4
by: Dean Card | last post by:
Okay, so here is the situation. I have need to do some on-the-fly image creation. I have everything working great except for the last part of it, applying a perspective type transform to the...
12
by: InvalidLastName | last post by:
We have been used XslTransform. .NET 1.1, for transform XML document, Dataset with xsl to HTML. Some of these html contents contain javascript and links. For example: // javascript if (a &gt; b)...
3
KevinADC
by: KevinADC | last post by:
If you are entirely unfamiliar with using Perl to sort data, read the "Sorting Data with Perl - Part One and Two" articles before reading this article. Beginning Perl coders may find this article...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.