Reputation: 505
I need to use variable in template match in xslt but I transformed template match into variable. I got syntax error.
This is my orginal xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/name/name[not(telephoneNav/detail/action = 'A') and not(telephoneNav/detail/action = 'S')]"/>
<xsl:template match="detail[not(action = 'A') and not(action = 'S')]"/>
</xsl:stylesheet>
This is my xslt which has been transformed into variable in template match.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:variable name="actionXpath1" select="'/name/name[not(telephoneNav/detail/action = 'A') and not(telephoneNav/detail/action = 'S')]'" />
<xsl:variable name="actionXpath2" select="'detail[not(action = 'A') and not(action = 'S')]'" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="$actionXpath1"/>
<xsl:template match="$actionXpath2"/>
</xsl:stylesheet>
like this https://xsltfiddle.liberty-development.net/3MvmXiw
Upvotes: 0
Views: 334
Reputation: 167716
In XSLT 3 using static parameters and _match
as a shadow attribute you can use
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0">
<xsl:param name="actionXpath1" static="yes" select="'/name/name[not(telephoneNav/detail/action = "A") and not(telephoneNav/detail/action = "S")]'" />
<xsl:param name="actionXpath2" static="yes" select="'detail[not(action = "A") and not(action = "S")]'" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template _match="{$actionXpath1}"/>
<xsl:template _match="{$actionXpath2}"/>
</xsl:stylesheet>
https://xsltfiddle.liberty-development.net/3MvmXiw/1
So you need to use an XSLT 3 processor and you need to use it in a way that allows setting static parameters, i.e. use an API specialized for XSLT 3 to support setting such parameters before the stylesheet is compiled.
Upvotes: 1