need help creating a function for transforming an xml document using xslt. I am able to copy the document using xsl:copy-of, however it's not copying the root of the source xml document. As shown below, the root of the xml should be <List xsi:noNamespaceSchemaLocation ~> :



<?xml version="1.0" encoding="UTF-8" ?>
<!-- Sample XML file generated by XMLSpy v2008 sp1 (http://www.altova.com) -->

<List xsi:noNamespaceSchemaLocation="List.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<B BID="SU">
<O OID="MN">
<S SName="BFirstTEST" Description="Test PDF" />
<S SName="ASecondTEST" Description="Test PDF" />
</O>
<B/>
</List>


The xslt transformation function I have follows:

Dim xmldocumentobject As XmlDocument

xmldocumentobject = New XmlDocument
Dim strfilepath As String = xmlFilePath

'Load the unsorted/current Xml file
xmldocumentobject.Load(strfilepath)

'Insert function to overwrite previous unsorted xmldocument with newly sorted newxmldocument

Dim str_sortedxmldoc As String
str_sortedxmldoc = XsltSortDoc(xmldocumentobject.ToString)

' Re-Load the transformed/sorted xml document into the xml document object
xmldocumentobject.LoadXml(str_sortedxmldoc)

'Then save xml document in configured file path
xmldocumentobject.Save(xmlFilePath)


Public Function XsltSortDoc(ByVal sXMLDocument As String) As String

Dim xd As XmlDocument
Dim xdNav As XPathNavigator
Dim tr As Xsl.XslCompiledTransform
Dim sw As StringWriter

xd = New XmlDocument()
xd.LoadXml(sXMLDocument)
xdNav = xd.CreateNavigator()
tr = New Xsl.XslCompiledTransform()
tr.Load(config.xsltFilePath)
sw = New StringWriter()
tr.Transform(xdNav, Nothing, sw)
Return sw.ToString()
End Function

The xslt file defining the transformation follows:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xslutput method="xml" indent="yes"/>


<!--Copy List and all nodes, namespaces, child nodes, and text from source xml doc-->
<!-- by using @*|*|text()|comment()|processing-instruction() or @* | node()-->
<xsl:template match="/">
<xsl:copy-of select="@* | node()"/>
</xsl:template>


<!--Match the S nodes
Copy the current node's top-level values(the tag and it's attributes,
but not it's descendents)-->
<xsl:template match="List">
<xsl:copy>
<!--Apply transformation to all S nodes.-->
<xsl:apply-templates select="S">
<!--For all Sname attributes, sort them
ascendingly according to their @SName attribute.-->
<xsl:sort select="@SName" order="ascending"/>

<!--Copy the entire node (include its descendantas)-->
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

The above code produces the following outputed xml file in the debugger. Notice that the <List xsi:noNameSpaceSchemaLocation ~> has been commented out by the transformation. This causes the transformation function to fail during runtime compilation. :



<?xml version="1.0" encoding="utf-8"?>
<!--Sample XML file generated by XMLSpy v2008 sp1 (http://www.altova.com)-->
<!--List xsi:noNamespaceSchemaLocation="List.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"-->

<List>
<B BID="SU">
<O OID="MN">
<S SName="BFirstTEST" Description="Test PDF" />
<S SName="ASecondTEST" Description="Test PDF" />
</O>
</B>
</List>

My IDE is Visual Basic .Net 2008. I need to reproduce the xml file with the SName attributes sorted in ascending order. Any help is appreciated. Thanks.