This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Number of node in list from stylesheet


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@epistemics.co.uk



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]