XSL. Evaluate expression

后端 未结 1 1203
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-26 09:18

Sorry for my English.

XSL 1.0. How can I to calculate expression from element or attribute value?

For example XML:



        
相关标签:
1条回答
  • 2021-01-26 09:57

    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>
    0 讨论(0)
提交回复
热议问题