XSLT处理带有标记的文本

时间:2014-05-08 19:22:26

标签: html xml xslt

我有以下XML:<a>Text with <b>stuff</b> here</a>

用我的代码:

<xsl:template match="*[local-name() = 'a'][namespace-uri()=namespace-uri(.)]">
    <xsl:value-of select="normalize-space(text()) "/><xsl:text> </xsl:text>
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="*[local-name() = 'b'][namespace-uri()=namespace-uri(.)]">
    <xsl:value-of select="normalize-space(text())"/><xsl:text> </xsl:text>
    <xsl:apply-templates/>
</xsl:template>

我只得到结果:

  

带有东西的文字

我想要的是:

  

在这里填写文字。

那么如何处理<b/>元素之后的剩余文本?

1 个答案:

答案 0 :(得分:1)

为什么这么复杂?如果这确实是您的XML输入:

<a>Text with <b>stuff</b> here</a>

然后是以下样式表:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="text" encoding="UTF-8"/>

<xsl:template match="/">
    <xsl:value-of select="a" />
</xsl:template>

</xsl:stylesheet>

将返回请求的*结果:

Text with stuff here

-
(*)除最后一段时间外,输入中不存在。