Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / October 2003

Tip: Looking for answers? Try searching our database.

Ordering xml using xsl in c#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Si - 24 Oct 2003 10:13 GMT
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
Colin Savage - 24 Oct 2003 11:28 GMT
Read :
XML Namespaces and How They Affect XPath and XSLT
http://msdn.microsoft.com/library/en-us/dnexxml/html/xml05202002.asp

Colin

> Hi,
>
[quoted text clipped - 69 lines]
>
> Simon

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.