469,140 Members | 1,207 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,140 developers. It's quick & easy.

Ordering xml using xsl in c#

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
Nov 15 '05 #1
2 1683
Read :
XML Namespaces and How They Affect XPath and XSLT
http://msdn.microsoft.com/library/en...ml05202002.asp

Colin

"Si" <si***********@herbertsmith.com> wrote in message
news:07****************************@phx.gbl...
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

Nov 15 '05 #2

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" <si***********@herbertsmith.com>
| Sender: "Si" <si***********@herbertsmith.com>
| Subject: Ordering xml using xsl in c#
| Date: Fri, 24 Oct 2003 02:13:59 -0700
| Lines: 73
| Message-ID: <07****************************@phx.gbl>
| 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
|

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Brendan.Collins | last post: by
2 posts views Thread by Ken Durden | last post: by
4 posts views Thread by Chris | last post: by
3 posts views Thread by marc | last post: by
33 posts views Thread by Benjamin M. Stocks | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.