472,371 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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

Similar topics

2
by: Ken Fine | last post by:
(originally posted to one of macromedia's groups; no help, so hopefully someone here can help me out. I'm using VBScript ASP.) When designing administrative interfaces to websites, we often need...
13
by: nospam | last post by:
NEWS.COM Amazon wins patent for ordering forms # 6,615,226 http://tinyurl.com/m7v8 http://news.com.com/2100-1017-5070569.html In its latest patent, the online retailing giant outlined a...
6
by: Brendan.Collins | last post by:
Hi I have a javascript problem that has been annoying me for two days now and thought that a javascript expert might have the magic solution. I am populating a table dynamically from the...
2
by: Ken Durden | last post by:
Is there any way to control ordering of items in intellisense via attributes? For example, I have the following enum: public enum ESeverity { Acceptable, Low, Medium,
4
by: Chris | last post by:
Any good routines or suggestions to assist me in re-ordering my records in my datagrid? i.e. I have a field in each record that is used for ordering (i.e. 1,2,3,4). I would like to implement a...
3
by: marc | last post by:
I want to create a strongly typed collection and use DictionaryBase I add a number of objects but when i loop through the list the data is ordered in a strange maner. How is this possible? Can...
33
by: Benjamin M. Stocks | last post by:
Hello all, I've heard differing opinions on this and would like a definitive answer on this once and for all. If I have an array of 4 1-byte values where index 0 is the least signficant byte of a...
4
ChrisWang
by: ChrisWang | last post by:
Dear all, I am reading the book "Core Python Programming". In the chapter talking about modules, it says the modules should follow this ordering: import Python Standard Library modules ...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.