EDN Admin
Well-known member
Hello,
We have a function in C# to take XML data and sort it using an XSLT style sheet, and then return the sorted data and put it into an XMLDocument object. The XSLT will process the data without error but it doesnt return all of the
data correctly. Im hoping someone can help me find the problem in the XSLT...
-----------------------------------------------
The "input" XML data looks like this:
<?xml version="1.0" encoding="UTF-8"?><br/>
<Root name="Team Services" url=" <br/>
<Node title="Site Tree Three http://server/departments/sitrtreethree" http://server/departments/sitrtreethree" /> <br/>
<Node title="AppSec http://server/sites/appsec" http://server/sites/appsec" /><br/>
<Node title="Julies test site http://server/sites/julie" http://server/sites/julie" /><br/>
</Root>
--------------------------------
The XSLT style sheet:
<?xml version="1.0" encoding="utf-8"?><br/>
<xsl:stylesheet version="1.0" xmlns:xsl=" http://www.w3.org/1999/XSL/Transform http://www.w3.org/1999/XSL/Transform "<br/>
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl <br/>
<xslutput method="xml" indent="yes"/>
<xsl:template match="@* | node() <br/>
<xsl:copy><br/>
<xsl:apply-templates select="@* | node()"/><br/>
</xsl:copy><br/>
</xsl:template>
<xsl:template match="Root <br/>
<xsl:copy><br/>
<xsl:apply-templates select="Node <br/>
<xsl:sort select="@title" data-type="text" order="ascending"/><br/>
</xsl:apply-templates><br/>
</xsl:copy><br/>
</xsl:template><br/>
</xsl:stylesheet>
---------------------------------------
And the resulting "output" XML:
<Root><br/>
<Node title="AppSec http://server/sites/appsec" rel=" _mce_href= http://server/sites/appsec " /><br/>
<Node title="Julies test site http://server/sites/julie" rel=" _mce_href= http://server/sites/julie " /><br/>
<Node title="Site Tree Three http://server/departments/sitrtreethree" rel=" _mce_href= http://server/departments/sitrtreethree " /><br/>
</Root>
As you can see, the "Root" node is missing its original attributes. i.e. <Root name="Team Services" url="
What should I do in the XSLT to keep the "Root" attributes intact in the output XML?
Many thanks for your help and expertise!
Regards,
Kevin Worthington
<
Kevin<br/>
View the full article
We have a function in C# to take XML data and sort it using an XSLT style sheet, and then return the sorted data and put it into an XMLDocument object. The XSLT will process the data without error but it doesnt return all of the
data correctly. Im hoping someone can help me find the problem in the XSLT...
-----------------------------------------------
The "input" XML data looks like this:
<?xml version="1.0" encoding="UTF-8"?><br/>
<Root name="Team Services" url=" <br/>
<Node title="Site Tree Three http://server/departments/sitrtreethree" http://server/departments/sitrtreethree" /> <br/>
<Node title="AppSec http://server/sites/appsec" http://server/sites/appsec" /><br/>
<Node title="Julies test site http://server/sites/julie" http://server/sites/julie" /><br/>
</Root>
--------------------------------
The XSLT style sheet:
<?xml version="1.0" encoding="utf-8"?><br/>
<xsl:stylesheet version="1.0" xmlns:xsl=" http://www.w3.org/1999/XSL/Transform http://www.w3.org/1999/XSL/Transform "<br/>
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl <br/>
<xslutput method="xml" indent="yes"/>
<xsl:template match="@* | node() <br/>
<xsl:copy><br/>
<xsl:apply-templates select="@* | node()"/><br/>
</xsl:copy><br/>
</xsl:template>
<xsl:template match="Root <br/>
<xsl:copy><br/>
<xsl:apply-templates select="Node <br/>
<xsl:sort select="@title" data-type="text" order="ascending"/><br/>
</xsl:apply-templates><br/>
</xsl:copy><br/>
</xsl:template><br/>
</xsl:stylesheet>
---------------------------------------
And the resulting "output" XML:
<Root><br/>
<Node title="AppSec http://server/sites/appsec" rel=" _mce_href= http://server/sites/appsec " /><br/>
<Node title="Julies test site http://server/sites/julie" rel=" _mce_href= http://server/sites/julie " /><br/>
<Node title="Site Tree Three http://server/departments/sitrtreethree" rel=" _mce_href= http://server/departments/sitrtreethree " /><br/>
</Root>
As you can see, the "Root" node is missing its original attributes. i.e. <Root name="Team Services" url="
What should I do in the XSLT to keep the "Root" attributes intact in the output XML?
Many thanks for your help and expertise!
Regards,
Kevin Worthington
<
Kevin<br/>
View the full article