使用XSLT展开元素

时间:2014-01-11 19:17:09

标签: xslt-1.0

我有大而复杂的文档,在文档的不同位置包含以下片段

<a>foo<b>bar</b><a>
<a>foo<b>bar</b><b>hello</b><a>

我想转换为

<b>foobar<b> 
<b>foobar<b><b>hello</b>

1 个答案:

答案 0 :(得分:0)

使用以下两个模板匹配器:

<xsl:template match="a">
    <xsl:apply-templates select="b"/>
</xsl:template>

<xsl:template match="b">
    <xsl:copy>
        <xsl:if test="position() = 1">
            <xsl:value-of select="parent::a/text()"/>
        </xsl:if>

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