[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Xpath and for-each looping

Subject: Xpath and for-each looping
From: Alan Gardner <scipiomedia@xxxxxxxxxxx>
Date: Fri, 16 May 2003 14:21:49 -0600
xpath for each
I've got a xml document (out.xml) that was generated from 3 other xml doc
(using the copy-of element), and I'm mostly happy with the results. The goal
is to loop through out.xml doc and display the last 5 title nodes (according
to their respective date).  The unintended result is that it loops through 3
times because of the three rdf:RDF tags that were pulled in when the xml
page was generated.

Here¹s some of the abbreviated code to illustrate what happened.

Out.xml:
<fxml  xmlns:fxml="http://www.utah.gov/fxml"
xmlns:rss="http://purl.org/rss/1.0/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
 
<rdf:RDF xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <item rdf:about="http://www.domain.com/path/file.ext">
        <title>sample1 title1</title>
        <link>http://http://www.domain.com/path/file.ext</link>
        <description>Description 1 goes here</description>
        <date>05/21/03</date>
     </item>
</rdf:RDF>
<rdf:RDF xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <item rdf:about="http://http://www.domain.com/path/file.ext">
        <title>sample2 title1</title>
        <link>http://http://www.domain.com/path/file.ext</link>
        <description>Description 2  goes here</description>
        <date>05/21/03</date>
    </item>
 </rdf:RDF>
  <rdf:RDF xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <item rdf:about="http://http://www.domain.com/path/file.ext">
        <title>sample3 title1</title>
        <link>http://http://www.domain.com/path/file.ext</link>
        <description>Description 1 goes here</description>
        <date>05/21/03</date>
    </item>
</rdf:RDF>
</fxml>

In my xsl doc I¹m doing this:
<xsl:apply-templates select="document('out.xml')/*"/>

<xsl:template match="fxml/rdf:RDF">
            <xsl:for-each select="item">
                <xsl:sort select="date" order="descending"/>
                <xsl:if test="position() &lt; 6">
                    <a href="{link}"><xsl:value-of select="title"/></a>
                    <xsl:text> </xsl:text>
                    <xsl:value-of select="date"/><br/>
                </xsl:if>
            </xsl:for-each>
            
    </xsl:template>

How do I write it to loop through just the item nodes once and sort them by
date?

Alan 



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.