Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 3rd, 2006, 05:45 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default sorting nested elements again

I am trying to find a way to sort the contents of an XML document not just by element ("section" in my example), but to also sort the elements in each of those elements ("para" in my example). The result should not seperate the "para" elements from their parent "section" elements when displayed.

My XML document looks like this:

<notes>
    <section sensing="2" intuitive="3">
        <title>Section One

    </title>
        <extra show="on">extra one
        </extra>

        <para sensing="1" intuitive="3">One para

    </para>
        <para sensing="3" intuitive="1">Two para

    </para>
    </section>
    <section sensing="1" intuitive="2">
        <title>Section two

    </title>
        <para sensing="1" intuitive="3">Three para

    </para>
        <para sensing="3" intuitive="1">Four para

    </para>
        <extra show="on">
        extra two
        </extra>

    </section>
    <section sensing="3" intuitive="1">
        <title>Section three

    </title>
        <para sensing="1" intuitive="3">Five para

    </para>
        <para sensing="3" intuitive="1">Six para

    </para>
        <extra show="on">
        extra three
        </extra>

    </section>
</notes>

The stylesheet that sorts this only by the "section" elements looks like this:


<xsl:template match="/">

<html>
    <head>
        <title></title>
    </head>
    <body>

 <xsl:apply-templates/>

    </body>
</html>


</xsl:template>

    <xsl:template match="notes">
    <xsl:apply-templates select="section">
    <xsl:sort select="@sensing" />
        </xsl:apply-templates>
</xsl:template>

<xsl:include href="notesx.xslt"/>

</xsl:stylesheet>

The "notesx" stylesheet looks like this:

<xsl:template match="section">
<h3><xsl:apply-templates select="title"/></h3>
<xsl:for-each select="para">
<p><xsl:value-of select="text()"/></p>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>



Why does the following stylesheet not work?

<xsl:template match="/">

<html>
    <head>
        <title></title>
    </head>
    <body>

<xsl:apply-templates/>


    </body>
</html>


</xsl:template>



  <xsl:template match="notes">

       <xsl:for-each select="section">
      <xsl:sort select="@intuitive"/>

             <xsl:for-each select="para">
                    <xsl:sort select="@intuitive" />

                </xsl:for-each>

        </xsl:for-each>
 </xsl:template>


<xsl:include href="notesx.xslt"/>

</xsl:stylesheet>




Reply With Quote
  #2 (permalink)  
Old June 5th, 2006, 03:38 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You code doesn;t actually generate any output within the nested for-each loops. Perhaps you took it out for clarity; but in that case you could have taken a lot of other things out for clarity as well, and you are asking us to debug code which is not the code you actually ran. If you are still having difficulty getting this to work please submit a complete example that's simplified as much as you can, showing the input, the stylesheet, the expected output and the actual output.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting Elements scopley XSLT 4 November 7th, 2007 11:14 AM
Problem nested elements Geierwally XSLT 7 May 9th, 2007 07:27 AM
transformation from attributes to nested elements e-bell XSLT 2 January 21st, 2007 07:21 PM
path for nested elements rjonk XSLT 7 November 20th, 2006 05:43 AM
sorting nested elements stekker XSLT 5 June 5th, 2006 01:19 AM



All times are GMT -4. The time now is 06:36 AM.


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