Altova Mailing List Archives

RE: [xsl] 'xsl:variable' as dynamic select for 'xsl:for-each'...

From: "Michael Kay" <mhk@--------->
Date: 11/17/2003 3:42:00 AM
> My problem is that the select statement of the variable needs to be 
> dynamic. Such as... (and I know this doesn't work.. )
>    <xsl:choose>
>      <xsl:when test="$clientid = ''">
>         <xsl:variable name="selectclause" select = "//client"/>
>      </xsl:when>
>      <xsl:otherwise>
>        <xsl:variable name="selectclause" select = 
> "//client[$clientid]"/>
>      </xsl:otherwise>
>    </xsl:choose>

This is a bit tricky in XSLT 1.0. The usual recommendation for creating
a node-set conditinoally is:

<xsl:variable name="selectclause" select="(//client)[$clientid=''] |

or more generically

   select = then-part[condition] | else-part[not(condition)] 

In XSLT 2.0 of course you can do

   select="if (condition) then expr-1 else expr-2"

Michael Kay

 XSL-List info and archive:


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.