【问题标题】:how to make proper selection through <xsl:value-of> tag?如何通过 <xsl:value-of> 标签进行正确选择?
【发布时间】:2013-03-14 05:55:17
【问题描述】:

以下是我的xml代码:

<abbr>
<title>world health organization</title>who</abbr>
was founded in 1948. 

在上面的代码中,我希望 xslt 输出为:

<abbr title="world health organisation">who<abbr>

我编写了以下 XSLT 代码:

<xsl:template match ="abbr">
&lt;abbr title="<xsl:value-of select ="title"/>"&gt;
<xsl:value-of select ="."/>&lt;/abbr&gt;
</xsl:template>

我得到了:

<abbr title="world health organization">
world health organizationwho</abbr>

我哪里做错了?

输出

<xsl:value-of select"."/> 

world health organisationwho

(世界卫生组织+谁)

现在,我不想要第一部分。 我怎样才能做到这一点?

【问题讨论】:

    标签: html xslt abbr


    【解决方案1】:

    由于titleabbr 的子代,title 的文本是abbr 字符串值的一部分。请试试这个:

    <xsl:template match ="abbr">
      <abbr title="{title}">
        <xsl:apply-templates select="text()"/>
      </abbr>
    </xsl:template>
    

    顺便说一句,您是否在 XSLT 中使用 xsl:output method="text"?如果您使用 XSLT 生成 XML,那么您应该使用 method="xml"。这就是 XSLT 的用途。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多