如何在模板匹配xslt中使用变量
我需要在xslt的模板匹配中使用变量,但我将模板匹配转换为变量。我有语法错误 这是我最初的xslt如何在模板匹配xslt中使用变量,xslt,xslt-1.0,xslt-2.0,Xslt,Xslt 1.0,Xslt 2.0,我需要在xslt的模板匹配中使用变量,但我将模板匹配转换为变量。我有语法错误 这是我最初的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&g
<?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>
这是我的xslt,它已在模板匹配中转换为变量
<?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>
类似于XSLT 3中的使用静态参数和\u match作为可以使用的阴影属性
<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>
因此,您需要使用XSLT 3处理器,并且需要以允许设置静态参数的方式使用它,即在编译样式表之前,使用专门用于XSLT 3的API来支持设置此类参数。变量存储值(示例中的字符串值),而不是匹配模式或其他XPath表达式。--另外,请选择XSLT 1.0或2.0,不要两者都选择。像这样,我不确定我应该从中学习什么。在XSLT 1.0中,“匹配属性的值包含VariableReference是一个错误。”在XSLT 2.0中,由于其他原因,您的尝试无法工作,正如我前面解释的。