XSL.评估表达 [英] XSL. Evaluate expression
本文介绍了XSL.评估表达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对不起我的英语.
XSL 1.0. 如何根据元素或属性值计算表达式?
XSL 1.0. How can I to calculate expression from element or attribute value?
例如 XML:
<position>
<localizedName>ref-help</localizedName>
<reference>concat('../help/', $lang, '/index.html')</reference>
</position>
我尝试使用来自 'reference' 属性的表达式:
I try use expression from 'reference' attribute:
<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>
但我得到字符串:
file:///C:/sendbox/author/application/support/concat('../help/',%20%24lang,%20'/index.html')
我如何评估它?
问候
推荐答案
如果您的 XSLT 处理器实现了 EXSLT扩展,您可以参考一个将字符串动态计算为 XPath 表达式的函数:
If your XSLT processor implements the EXSLT extensions, you can reference a function that dynamically evaluates strings as XPath expressions:
<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>
注意:
- 无需在使用前将内容保存在变量中
- 有一个
current()
函数你可能错过了 - 使用
和
支持
>
- there is no need to save things in a variable before using them
- there is a
current()
function you might have missed - use
<xsl:apply-templates>
and<xsl:template>
in favor of<xsl:for-each>
这篇关于XSL.评估表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文