如何使用value-of忽略特定元素值

时间:2014-02-28 07:29:43

标签: xslt xslt-1.0 xslt-grouping

在我的输入下面

<root>
<text>
 <bold>Co<csc>lorado DivIs</csc>IoN</bold>
</text>
<text>
 fi<csc>ve and a ha</csc>lf <x>abc</x>
</text>
</root>

这是我的xslt我的实现(xslt verions-1.0)

<xsl:for-each select="/root/text">
    <xsl:value-of select="./child::*[local-name(.)!='x']" />
  <xsl:text> </xsl:text>
</xsl:for-each>

正确的输出如下所示,应该只忽略'x'元素值。

Colorado DivIsIoN five and a half

我得到的输出是缺少当前元素文本。

 Colorado DivIsIoN ve and a ha

2 个答案:

答案 0 :(得分:2)

以这种方式试试吗?

<xsl:template match="/">
    <xsl:for-each select="root/text">
        <xsl:for-each select=".//text()[not (parent::x)]">
            <xsl:value-of select="." />
        </xsl:for-each>
        <xsl:text> </xsl:text>
    </xsl:for-each>
</xsl:template>

答案 1 :(得分:0)

试试这个

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="UTF-8" indent="yes"/>
    <xsl:template match="root">

      <xsl:apply-templates select="@*|node()"/>

  </xsl:template>

  <xsl:template match="text/x"/>

  <xsl:template match="@* | node()">

      <xsl:apply-templates select="@* | node()"/>

  </xsl:template>

<xsl:template match="text()">
<xsl:value-of select="."/>
</xsl:template> 

</xsl:stylesheet>
相关问题