Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 5th, 2004, 08:39 AM
Registered User
 
Join Date: Apr 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Simple question about XSLT

Hello,


I'm new to xslt and xml. I have a xml-document that looks like this :

<?xml version="1.0" standalone="yes"?>
<sessions version="1.0">
  <session name="Development">
    <libraries>
      <library name="contxtlib">
        <fullname>123</fullname>
        <super>true</super>
        <loadorder>8</loadorder>
      </library>
      <library name="xmllib">
        <fullname>xmllib.p</fullname>
        <super>true</super>
        <loadorder>12</loadorder>
      </library>
      <library name="clientdebuglib">
        <fullname>clientdebuglib.p</fullname>
        <super>true</super>
        <loadorder>3</loadorder>
      </library>
    </libraries>
  </session>
</sessions>

Now i want to sort this xml-file. The loadorder should be 3 then 8 and then 12 and not in this order. So it has to be sorted. I tried writing a xslt file but he doesn't sort my data.
My xslt file looks like this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="session">
    <xsl:copy>
      <xsl:apply-templates>
         <xsl:sort data-type="number" select="session/libraries/library/loadorder"/>
         </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="*">
    <xsl:copy>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

Everything could be wrong for me, i found this on the internet and made some changes but now i don't know whether it's good. All i want to to is sort the library's on loadorder.

thx a lot in advance

 
Old May 5th, 2004, 08:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

All you need for this is a single template in your xsl file:
Code:
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()">
                <xsl:sort data-type="number" select="loadorder"/>
            </xsl:apply-templates>
        </xsl:copy>
    </xsl:template>
Basically, as the xslt processor goes through your xml document it will attempt to apply the sort to each node-set, but the only node that contains a "loadorder" child element is the library node, so the sort will effectively be ignored for all other nodes.

hth
Phil
 
Old May 5th, 2004, 09:31 AM
Registered User
 
Join Date: Apr 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thx a lot!!
With my xml i still had a problem because he didn't copy the attributes but with yours he does everything perfectly THX!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple XSLT Problem (HELP PLEASE) gaeawalker XSLT 2 October 10th, 2007 10:27 AM
simple XSLT apply-templates question fannus XSLT 7 March 27th, 2007 02:11 AM
simple XSLT question _thinking XSLT 4 January 24th, 2006 10:41 AM
simple xml / xslt example needed badgolfer ASP.NET 1.0 and 1.1 Basics 2 January 21st, 2005 02:10 AM
XSLT simple parsing problem misu XSLT 3 August 18th, 2004 02:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.