Subject: Re: [xsl] Getting the first and last nodes of a sorted nodeset From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Thu, 08 Apr 2004 11:10:33 -0400 |
Cheers, Wendell
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>
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Getting the first and last no, Hansen, John | Thread | Re: [xsl] Getting the first and las, Wendell Piez |
Re: [xsl] Can I change variable con, Mukul Gandhi | Date | RE: [xsl] How to put space between , puja thakral |
Month |