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

Re: Number of node in list from stylesheet

Subject: Re: Number of node in list from stylesheet
From: Jeni Tennison <Jeni.Tennison@xxxxxxxxxxxxxxxx>
Date: Tue, 23 May 2000 15:19:39 +0100
number of node xsl
Sebastian,

>why pass the monthname as parameter, as opposed to 
>
>select="document('')//foo:month[@name=$monthName] " mode="getNumber"
>
>? doesnt that the work the same way, and look more natural?

You're quite right that that would work if the $monthName was defined as a
top-level variable, and is more elegant.

I didn't make clear that I was assuming the $monthName variable was defined
within a template rather than at a top level, and thus inaccessible to
other templates aside from by passing it through as a parameter.  This is
necessary in Cheun's case because each product defines a best-before date,
each of which has to be converted into a number to be compared with today's
date.

Actually, in the real case $monthName isn't even defined except within the
parameter.  Here's the full template:

<xsl:template match="STUFF/*">
  <xsl:param name="today" />
  <xsl:variable name="bbString" select="BESTBEFORE" />
  <xsl:variable name="bbDay"
select="format-number(number(substring-before(BESTBEFORE, ' ')), '00')" />
  <xsl:variable name="bbMonth">
    <xsl:apply-templates select="document('')//foo:month" mode="getNumber">
      <xsl:with-param name="monthName"
select="substring-before(substring-after($bbString, ' '), ' ')" />
    </xsl:apply-templates>
  </xsl:variable>
  <xsl:variable name="bbYear"
select="substring-after(substring-after(BESTBEFORE, ' '), ' ')" />
  <xsl:variable name="bb" select="number(concat($bbYear, $bbMonth,
$bbDay))" />
  <xsl:element name="{name()}">
    <xsl:copy-of select="BESTBEFORE" />
    <CONDITION>
      <xsl:choose>
        <xsl:when test="$today &gt; $bb">
          <xsl:text>expired</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="CONDITION" />
        </xsl:otherwise>
      </xsl:choose>
    </CONDITION>
  </xsl:element>
</xsl:template>

Thanks,

Jeni

Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 ? Fax 0115 9061304 ? Email
jeni.tennison@xxxxxxxxxxxxxxxx



 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.