Reputation: 1103
I have a simple question. How do you combine a path from two template parameters? I would like to do something like that:
<xsl:template match="*[namespace-uri()='show:show']">
<xsl:param name="arg1"/>
<xsl:param name="arg2"/>
<tr>
<td>
<xsl:value-of select="concat($arg1,$arg2)"/>
</td>
</tr>
to get path like: arg1/arg2 but it doesn't work. How can I do that properly?
or can you do sth like
<xsl:value-of select="path/path/$arg2"/>
?
arg1 is complete path from root and arg2 is single element name.
Upvotes: 1
Views: 2095
Reputation: 122374
To build path expressions as strings and then evaluate them you need an extension function (at least in XSLT 1.0 and 2.0), there's nothing in the core spec to support it but most processors provide a suitable function. The expression
<xsl:value-of select="concat($arg1,'/',$arg2)"/>
would result in a string containing the string value of arg1
, a slash, and the string value of arg2
. But if arg1 is a node set and you restrict arg2 to be just an element name then you can do something like this
<xsl:value-of select="$arg1/*[local-name() = $arg2]"/>
(or copy-of
as appropriate) and call the template like
<xsl:with-param name="arg1" select="/path/to/interesting/stuff" />
<xsl:with-param name="arg2" select="'elementname'" />
If you wanted to allow for arg2 to name an attribute rather than an element use
$arg1/@*[.....]
Or to allow it to be either (assuming the target of arg1
doesn't have an attribute and a child element with the same name)
$arg1/node()[......]
Upvotes: 2
Reputation: 11298
You can do like this
<xsl:value-of select="concat($arg1,'/',$arg2)"/>
Upvotes: 0