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

Getting the first and last nodes of a sorted nodeset

Subject: 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
jon from first to last
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

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.