Subject: RE: [xsl] Making XPath expressions out of variables From: Jarno.Elovirta@xxxxxxxxx Date: Wed, 29 Oct 2003 15:32:08 +0200 |
Hi, > This is a theoretical bit of XSL code which I need a > practical version of: > > All the variables are passed as parameters to the stylesheet. > > <xsl:for-each select="//$record-type"> > <xsl:sort select="$sort-by" order="$sort-order" /> > <xsl:if test="$lh-operator $operand $rh-operator"> > <tr> > <xsl:for-each select="*"> > <td><xsl:value-of select="." /></td> > </xsl:for-each> > </tr> > </xsl:if> > </xsl:for-each> > > Any ideas? Is it possible? Or do I need to use this basic > construct multiple > times using <xsl:if> for each variable and the correct names > of nodes and > operands. (The number of permutations is massive!) You can create a template <xsl:template name="comparison"> <xsl:param name="operator"/> <xsl:param name="lh"/> <xsl:param name="rh"/> <xsl:choose> <xsl:when test="$operator '='"> <xsl:value-of select="$lh = $rh"/> </xsl:when> ... </xsl:choose> </xsl:template> that contains the operator functionality and use it with <xsl:variable name="result"> <xsl:call-template name="comparison"> <xsl:with-param name="operator" select="$operand"/> <xsl:with-param name="lh" select="$lh-operator"/> <xsl:with-param name="rh" select="$rh-operator"/> </xsl:call-template> </xsl:variable> <xsl:if test="$result = 'true'"> ... See FXSL <http://fxsl.sourceforge.net/>. > Is there a way of selecting nodes which have the name > $some-variable using an > XPath expression? > > e.g. <xsl:for-each select="//$some-variable"> > > would, in theory (though not in practice - I've tried it!), > select all the > nodes whose name is equal to whatever the value of $some-variable is. <xsl:for-each select="//*[local-name() = $some-variable]"> Cheers, Jarno - Velvet Acid Christ: Futile (Resisted mix by Funker Vogt) XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Making XPath expressions , Michael Kay | Thread | RE: [xsl] Making XPath expressions , Sergiu Ignat |
[xsl] Making XPath expressions out , Richard Lewis | Date | Re: [xsl] Making XPath expressions , David Carlisle |
Month |