Re: [xsl] Comparing element values

Subject: Re: [xsl] Comparing element values
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 4 Oct 2004 15:58:22 +0100
> How do I adapt the code below to accept variables?

The restriction on variables in match patterns (which was intend to make
it harder to have circular definitions of variables) is fairly pointless
(and removed in xslt2 draft) as you can almost always change

match="fzds[jkhfjf using a variable]">

to


match="fzds">
<xsl:if test="jkhfjf using a variable">
....
perhaps with some slight changes in program logic,
so the restriction is really just a syntactic annoyance rather than a
real restriction.


so in this case:

<xsl:template match="price">
  <xsl:param name="n" select="3"/>
  <xsl:choose>
  <xsl:when test="position()=$n and . &gt; following-sibling::price[1]"/>
  <xsl:when test="position()=($n + 1) and . &gt;= preceding-sibling::price[1]]"/>
  <xsl:otherwise>
  <xsl:copy-of select="."/>
  </xsl:otherwise>
  </xsl:choose>
</xsl:template>


Note here that you need to call this via:

<xsl:apply-templates select="price"/>

rather than just


<xsl:apply-templates/>

otherwise the price elements will have postion()'s 2,4,6,8, rather than
1,2,3,4 as there are white space text nodes in the odd positions.

(This isn't needed in the version I posted before as there position()
was filtering the price step explictly)

David


________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread