【问题标题】:Setting xsl:value-of into an href attribute and the text field of a link in an XSLT将 xsl:value-of 设置为 href 属性和 XSLT 中链接的文本字段
【发布时间】:2011-02-03 12:23:35
【问题描述】:

如何通过 XSLT 转换设置既是链接又具有链接文本的 href?这是我到目前为止所拥有的,这给了我错误“xsl:value-of cannot be a child of the xsl:text element”:

<xsl:element name="a">
   <xsl:attribute name="href">
      <xsl:value-of select="actionUrl"/>
   </xsl:attribute>
   <xsl:text><xsl:value-of select="actionUrl"/></xsl:text> 
</xsl:element>

【问题讨论】:

    标签: xml xslt href


    【解决方案1】:

    &lt;xsl:text&gt; 定义 XSL 文档中的文本部分。只有真实的纯文本可以到这里,而不是 XML 节点。你只需要&lt;xsl:value-of select="actionUrl"/&gt;,它无论如何都会打印文本。

    <xsl:element name="a">
        <xsl:attribute name="href">
            <xsl:value-of select="actionUrl"/>
        </xsl:attribute>
        <xsl:value-of select="actionUrl"/>
    </xsl:element>
    

    【讨论】:

    • 请注意,首先提名 href 并像您所做的那样显示文本似乎很重要。我有它的其他方式它无法显示。
    • 这很庞大且难以阅读,请查看lexicore's answer
    【解决方案2】:

    你也可以这样做:

    <a href="{actionUrl}"><xsl:value-of select="actionUrl"/></a>
    

    【讨论】:

    • 谢谢,Dimitre,一个错字。最近 EL 太多了。
    • 实际上,actionurl 不是一个变量——只是一个元素名称。因此,thete 名称的开头不能有“$”符号。
    【解决方案3】:

    您不需要xsl:text 元素:

    <xsl:element name="a">
      <xsl:attribute name="href">
        <xsl:value-of select="actionUrl"/>
      </xsl:attribute>
      <xsl:value-of select="actionUrl"/>
    </xsl:element>
    

    【讨论】:

      猜你喜欢
      • 2011-11-25
      • 1970-01-01
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 2021-05-20
      相关资源
      最近更新 更多