Subject: [xsl] Getting the first and last nodes of a sorted nodeset From: "Hansen, John" <John.Hansen@xxxxxxxxxx> Date: Wed, 7 Apr 2004 10:07:39 -0700 |
Is it possible in XSLT to call a template one time where the 2 parameters are the first and last nodes in a sorted nodeset? A friend of mine is trying to get a sorted list of dates and generate output for all dates from the first to the last (whether they appear in the original XML or not) via a named template which can take a start date and a stop date and generate output for all the dates from start to stop. I can't think of any way to do it. <?xml-stylesheet type="text/xsl" href="test.xsl"?> <root> <test> <nd>2003-12-31</nd> <nd>2004-01-01</nd> <nd>2004-01-02</nd> <nd>2004-01-03</nd> <nd>2004-01-04</nd> <test> <nd>2004-01-06</nd> <nd>2004-01-03</nd> <nd>2004-03-01</nd> </test> </test> <test> <nd>2004-02-08</nd> <nd>2004-01-02</nd> <nd>2004-02-03</nd> <nd>2004-01-04</nd> <nd>2004-02-08</nd> </test> </root> <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'> <xsl:output method='html'/> <xsl:key name='nd_key' match='nd' use='.'/> <xsl:template match="/root"> <html> <xsl:for-each select="//nd[generate-id()=generate-id(key('nd_key',.)[1])]"> <xsl:sort select="."/> <xsl:value-of select="."/><br/> <xsl:if test="position()=last()"> <xsl:call-template name="test_template"> <!-- first element ?? What to replace select="." with ?? --> <xsl:with-param name="b"><xsl:value-of select="."/></xsl:with-param> <!-- last element --> <xsl:with-param name="c"><xsl:value-of select="."/></xsl:with-param> </xsl:call-template> </xsl:if> </xsl:for-each> </html> </xsl:template> <xsl:template name="test_template"> <xsl:param name="b"></xsl:param> <xsl:param name="c"></xsl:param> <xsl:value-of select="$b" /> <xsl:value-of select="$c" /> </xsl:template> </xsl:stylesheet>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Use of moded templates?, M. David Peterson | Thread | Re: [xsl] Getting the first and las, Wendell Piez |
RE: [xsl] Use of moded templates?, M. David Peterson | Date | RE: [xsl] Getting the first and las, Hansen, John |
Month |