XSL。评估表达

问题描述:

对不起,我的英语。XSL。评估表达

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')

我该如何评估它?

问候

如果您的XSLT处理器实现了EXSLT扩展,你可以参考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()功能,你可能错过了
  • 使用<xsl:apply-templates><xsl:template>赞成<xsl:for-each>
+0

我使用的浏览器(Internet Explorer 9中,谷歌Chrome 18.0.1025.151 m和Safari浏览器5.1.5)。表达'dyn:评估'不起作用。 :((((( – 2012-04-06 16:37:29

+0

)然后你运气不好,必须使用不同的方法评估字符串作为表达式不是内置到XSLT中你有没有想过在服务器端进行转换 – Tomalak 2012-04-06 16:41:06

+0

不幸的是,这些文件放在本地计算机上 – 2012-04-06 16:47:43