Re: [xsl] Avoiding multiple "apply-templates" by creating one variable for the clauses. Is it possible?

Subject: Re: [xsl] Avoiding multiple "apply-templates" by creating one variable for the clauses. Is it possible?
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Thu, 20 Aug 2009 11:46:33 +0100
2009/8/20 Kate Busch-Petersen <kate.busch-petersen@xxxxxxxxxxxxx>:
> Hello,
>
> I'm currently working on creating a blog in asp.net, using XML and XSLT
2.0.
>
> In the past (working with XSLT 1.0) I've used multiple "apply-templates" to
handle all the possible param combinations, but I am looking for a more
manageable solution.
>
> Current method:
>
>    <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>

How about:

<xsl:apply-templates select="//blog[author_id = ($AuthorId,
author_id)[1]][category_id = ($CategoryId, category_id)[1]]"/>

...although there might be a nicer way.  Even so, sometimes its better
to have more readable code spread over a few lines than one that takes
you a few goes to understand what it's doing :)




--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

Current Thread