Subject: [xsl] Xpath and for-each looping From: Alan Gardner <scipiomedia@xxxxxxxxxxx> Date: Fri, 16 May 2003 14:21:49 -0600 |
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() < 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] table column, Wendell Piez | Thread | Re: [xsl] Xpath and for-each loopin, Peter Flynn |
[xsl] table column, Fei Zheng | Date | [xsl] XSL Filtering Question, Grant, Kathryn --- S |
Month |