xslt - How to use XSL variable in xsl:apply-templates? -
i have reasonably complex call xsl:apply-templates:
<xsl:apply-templates select="columnval[@id , not(@id='_name_') , not(@id='group') , not(@id='_count_')]"/>
the expression reused in other places this:
<xsl:apply-templates select="someothernode[@id , not(@id='_name_') , not(@id='group') , not(@id='_count_')]"/>
i want generalize somehow, can define once , reuse elsewhere. however, doesn't seem work:
<xsl:variable name="x">@id , not(@id='_name_') , not(@id='group') , not(@id='_count_')</xsl:variable> <xsl:apply-templates select="columnval[$x]"/> <xsl:apply-templates select="someothernode[$x]"/>
is there better / different way of doing this? want reuse xpath expression in multiple different calls xsl:apply-templates (some of select different children).
this going used in client application, can't use extensions or switch xslt 2 unfortunately. :(
thanks.
you can't construct xpath dynamically in xslt (at least, not xslt 1.0). can accomplish you're trying using template modes:
<xsl:apply-templates select="columnval" mode="filter"/> <xsl:apply-template select="someothernode" mode="filter"/> ... <!-- guarantees elements don't match filter don't output --> <xsl:template match="*" mode="filter"/> <xsl:template match="*[@id , not(@id='_name_') , not(@id='group') , not(@id='_count_')]" mode="filter"> <xsl:apply-templates select="." mode="filtered"/> </xsl:template> <xsl:template match="columnval" mode="filtered"> <!-- applied columnval elements pass filter --> </xsl:template> <xsl:template match="someothernode" mode="filtered"> <!-- applied someothernode elements pass filter --> </xsl:template>
Comments
Post a Comment