使用 XSLT,我试图去除特定节点内的所有标签,同时保留这些标签之间的空白。
我得到这样的 XML:
<text>
<s id="s2"> The patient is a <p id="p22">56-year-old</p> <p id="p28">Caucasian</p> <p id="p30">male</p></s></text>
我想去掉所有的 <s> 和 <p> 标记,以便在 <text> 节点中只有英文句子。
我尝试了以下模板,它确实成功删除了所有标签,但如果那里没有其他字符,它也会删除 <p> 标签之间的空格。例如,我最终会得到:“患者是一位 56 岁的白人男性”
<xsl:template name="strip-tags">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text, '<')">
<xsl:value-of select="substring-before($text, '<')"/>
<xsl:call-template name="strip-tags">
<xsl:with-param name="text" select="substring-after($text, '>')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
有什么想法吗?谢谢!