对不起我的英语不好。
XSL 1.0.如何从元素或属性值计算表达式?
例如 XML:
<position>
<localizedName>ref-help</localizedName>
<reference>concat('../help/', $lang, '/index.html')</reference>
</position>
我尝试使用“引用”属性中的表达式:
<xsl:for-each select="/content/positions/position">
<li>
<!--Save expression to variable...-->
<xsl:variable name="path" select="reference"/>
<!--Evaluate variable and set it value to 'href'-->
<a target="frDocument" href="{$path}">
<xsl:variable name="x" select="localizedName"/>
<xsl:value-of select="$resources/lang:resources/lang:record[@id=$x]"/>
</a>
</li>
</xsl:for-each>
但我得到字符串:
文件:///C:/sendbox/author/application/support/concat('../help/',%20%24lang,%20'/index.html')
我该如何评价它?
Regards
如果您的 XSLT 处理器实现EXSLT http://www.exslt.org/扩展,可以参考动态将字符串计算为 XPath 表达式的函数 http://www.exslt.org/dyn/functions/evaluate/index.html:
<xsl:stylesheet
version="1.0"
xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:dyn="http://exslt.org/dynamic"
extension-element-prefixes="dyn"
>
<xsl:template match="content">
<xsl:apply-templates select="positions/position" />
</xsl:template>
<xsl:template match="position">
<li>
<a target="frDocument" href="{dyn:evaluate(reference)}">
<xsl:value-of select="
$resources/lang:resources/lang:record[@id=current()/localizedName]
"/>
</a>
</li>
</xsl:template>
</xsl:stylesheet>
Note:
- 在使用之前不需要将它们保存在变量中
- 有一个
current()
您可能错过的功能
- use
<xsl:apply-templates>
and <xsl:template>
有利于<xsl:for-each>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)