user5182503
user5182503

Reputation:

Simple match with parameter using XSLT 2.0

This is my xsl code without parameter

<xsl:template match="node-name">
 ....
</xsl:template>

Now I want to use a parameter instead of node-name. So I added:

<xsl:param name="someParam"/>
 ...

<xsl:template match="$someParam">
 ....
</xsl:template>

However, it doesn't work. On SO I found only one question about parameter in match (xsl: how to use parameter inside "match"?) but it has a more complicated case, then I need. Could anyone help me?

Upvotes: 0

Views: 110

Answers (2)

Martin Honnen
Martin Honnen

Reputation: 167401

If that is a global parameter, then, if you use an XSLT 3 processor like Saxon 9.8 or later or Altova 2017 R3 or later you could consider using a static parameter <xsl:param name="node-name" static="yes" select="'foo'"/> and a shadow attribute <xsl:template _match="{$node-name}">.

Upvotes: 0

Michael Kay
Michael Kay

Reputation: 163262

Use match="*[local-name()=$node-name]"

Take care with namespaces.

Note also that this isn't allowed in XSLT 1.0, only in 2.0+.

Upvotes: 0

Related Questions