xml - 为什么上下文节点获得两次输出?

标签 xml xslt

要消除内部 para 元素,但在逐项列表中的后续 para 元素之间放置一个 br 元素,给定的 xml 如下所示:

    <listitem>
        <para>The application of power invokes the POR state machine(PORSM). During
        this time, the following registers are initialized:</para>
        .
        .
        .
        <para>In addition, the JTAG interface is disabled and the SSBD is
        open.</para>
     </listitem>

我写了一个如下的模板:

 <xsl:template match="listitem/para">
 <xsl:value-of select="."/>
<xsl:if test="count(./following-sibling::para) > 0">
<xsl:element name="br"/> 
</xsl:if>
<xsl:apply-templates/>
 </xsl:template>

我得到了 br,但是初始的 para 元素被重复了:

  The application of power invokes the POR state machine
        (PORSM). During this time, the following registers are
        initialized:
    <br/>The application of power invokes the POR state machine
        (PORSM). During this time, the following registers are
        initialized:

我知道这是一个新手问题,但是有人可以解释为什么我会重复当前的文本节点吗?

谢谢

拉斯

最佳答案

第一个副本来自

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

第二个来自

<xsl:apply-templates/>

它将模板应用于 para 元素的所有子节点。子节点包括文本节点和元素节点,如果您没有指定显式模板来匹配 text(),则文本节点的默认模板会将文本输出到结果树。

关于xml - 为什么上下文节点获得两次输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16844596/

相关文章:

mysql - 在将 XML 值插入 MySQL 表之前修改列

java - 以下 xml 需要 xslt 输出

Java XPath : Queries with default namespace xmlns

xpath - XSLT 根据条件更改特定元素的属性值

javascript - javascript 中的 xsl 转换器?

xml - xslt-单独替换 namespace uri

xml - 在xsl tokenize中,如何获取前面的文本值

xslt - 我们如何将 XML 元素转换为 xslt 中的不同 namespace

xml - 使用 XSL 合并和排序多个 XML 文件

java - 如何根据 xslt 中的特定值检查所有列表节点字段?