Ordering xml using xsl in c#

S

Si

Hi,

I have a xml dataset I'd like to order, and save in that
order. I've written an xsl to do the transformation, but
because the xml file has a xsd namespace, it doesn't work.

A cutdown version of the xml file looks like this:

<?xml version="1.0" standalone="yes"?>
<hsPrinters xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xmlns="http://tempuri.org/printer.xsd">
<city>
<code>LN</code>
<name>London</name>
<comment>Herbert Smith London Offices</comment>
</city>
<city>
<code>PA</code>
<name>Paris</name>
<comment>Herbert Smith Paris Offices</comment>
</city>
<city>
<code>BR</code>
<name>Brussels</name>
<comment>Brussels Offices</comment>
</city>
<city>
<code>MW</code>
<name>Moscow</name>
<comment>Moscow Office</comment>
</city>
</hsPrinters>

This is the xsl:

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="hsPrinters">
<hsPrinters xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xmlns="http://tempuri.org/printer.xsd">
<xsl:for-each select="city">
<xsl:sort select="code" order="ascending"/>
<city>
<xsl:copy-of select="code"/>
<xsl:copy-of select="name"/>
<xsl:copy-of select="comment"/>
</city>
</xsl:for-each>
</hsPrinters>
</xsl:template>
</xsl:stylesheet>

Like I said if I take out the namespace from the
<hsprinter>, the transform works, but then I cannot load
the xml doc into my dataset in c#.

c# tranform code I'm using is:

System.Xml.XPath.XPathDocument xmldoc = new
System.Xml.XPath.XPathDocument(info[1] + info[0]);
System.Xml.Xsl.XslTransform xfm = new
System.Xml.Xsl.XslTransform();
xfm.Load("c:\printer.xsl");
System.Xml.XmlTextWriter writer = new
System.Xml.XmlTextWriter("c:\printer.xsl"null);
xfm.Transform(xmldoc, null, writer);

I'd be grateful for any pointers

Many thanks

Simon
 
J

Jeffrey Tan[MSFT]

Hi Si,

I found that this post has been posted in several queues.
A customer member has replied you in
microsoft.public.dotnet.xml,microsoft.public.xsl, please follow up there.
My colleague will monitor you post there.
Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "Si" <[email protected]>
| Sender: "Si" <[email protected]>
| Subject: Ordering xml using xsl in c#
| Date: Fri, 24 Oct 2003 02:13:59 -0700
| Lines: 73
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOaDyjNf/lI1IyeQiaWU/rtnK2QwA==
| Newsgroups:
microsoft.public.dotnet.languages.csharp,microsoft.public.dotnet.xml,microso
ft.public.xsl
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.xml:16825
microsoft.public.xsl:30715 microsoft.public.dotnet.languages.csharp:193755
| NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi,
|
| I have a xml dataset I'd like to order, and save in that
| order. I've written an xsl to do the transformation, but
| because the xml file has a xsd namespace, it doesn't work.
|
| A cutdown version of the xml file looks like this:
|
| <?xml version="1.0" standalone="yes"?>
| <hsPrinters xmlns:xsi="http://www.w3.org/2001/XMLSchema-
| instance" xmlns="http://tempuri.org/printer.xsd">
| <city>
| <code>LN</code>
| <name>London</name>
| <comment>Herbert Smith London Offices</comment>
| </city>
| <city>
| <code>PA</code>
| <name>Paris</name>
| <comment>Herbert Smith Paris Offices</comment>
| </city>
| <city>
| <code>BR</code>
| <name>Brussels</name>
| <comment>Brussels Offices</comment>
| </city>
| <city>
| <code>MW</code>
| <name>Moscow</name>
| <comment>Moscow Office</comment>
| </city>
| </hsPrinters>
|
| This is the xsl:
|
| <xsl:stylesheet
| xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
| version="1.0">
| <xsl:template match="hsPrinters">
| <hsPrinters xmlns:xsi="http://www.w3.org/2001/XMLSchema-
| instance" xmlns="http://tempuri.org/printer.xsd">
| <xsl:for-each select="city">
| <xsl:sort select="code" order="ascending"/>
| <city>
| <xsl:copy-of select="code"/>
| <xsl:copy-of select="name"/>
| <xsl:copy-of select="comment"/>
| </city>
| </xsl:for-each>
| </hsPrinters>
| </xsl:template>
| </xsl:stylesheet>
|
| Like I said if I take out the namespace from the
| <hsprinter>, the transform works, but then I cannot load
| the xml doc into my dataset in c#.
|
| c# tranform code I'm using is:
|
| System.Xml.XPath.XPathDocument xmldoc = new
| System.Xml.XPath.XPathDocument(info[1] + info[0]);
| System.Xml.Xsl.XslTransform xfm = new
| System.Xml.Xsl.XslTransform();
| xfm.Load("c:\printer.xsl");
| System.Xml.XmlTextWriter writer = new
| System.Xml.XmlTextWriter("c:\printer.xsl"null);
| xfm.Transform(xmldoc, null, writer);
|
| I'd be grateful for any pointers
|
| Many thanks
|
| Simon
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top