XSL. Evaluate expression

北慕城南 提交于 2019-12-02 08:41:28

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>

Note:

  • 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>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!