Subject: Re: Avoiding multiple "apply-templates" by creating one variable for the clauses. Is it possible?
From: Michael Schäfer <michael.schaefer@xxxxxxxxxxx>
Date: Thu, 20 Aug 2009 13:30:54 +0200
|
Hi,
<xsl:choose>
<xsl:when test="$AuthorId">
<xsl:apply-templates select="//blog[author_id = $AuthorId]"/>
</xsl:when>
<xsl:when test="$CategoryId">
<xsl:apply-templates select="//blog[category_id = $CategoryId]"/>
</xsl:when>
<xsl:when test="$AuthorId and $CategoryId">
<xsl:apply-templates select="//blog[author_id = $AuthorId and category_id = $CategoryId]"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="//blog"/>
</xsl:otherwise>
</xsl:choose>
Would this code have worked anyway? The XSLT 2.0 spec (8.2) reads:
"The content of the first, and only the first, xsl:when element that is
satisfied is evaluated". I suppose it's the same in XSLT 1.0.
So I wonder if the third xsl:when would execute at all, because if either
$AuthorId or $CategoryId evaluate to true, one of the first two xsl:when
should be satisfied.
Michael
* michael.schaefer@xxxxxxxxxxx http://www.destatis.de
* http://www.statspez.de
|