【发布时间】:2019-03-11 15:13:00
【问题描述】:
我有以下虚拟 xml 文件,我需要去除 TXT 中的标签。我已经创建了一个样式表,它成功地去除了文件中的 all 标记,但我只希望它只去除 TXT 块中的标记 within。我需要对 XSLT 进行哪些更改才能实现此目的?
XML
<DOC>
<ID>1234</ID>
<TXT>
<A><DESC type="PERSON">George Washington</DESC> lived in a house called <DESC type="PLACE">Mount Vernon.</DESC></A>
<A><DESC type="PERSON">Thomas Jefferson</DESC> lived in a house called <DESC type="PLACE">Monticello.</DESC></A>
</TXT>
</DOC>
XSLT
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="strip-tags">
<xsl:param name="TXT"/>
<xsl:choose>
<xsl:when test="contains($TXT, 'A')">
<xsl:value-of select="$TXT"/>
<xsl:call-template name="strip-tags">
<xsl:with-param name="TXT" select="substring-after($TXT, 'A')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$TXT"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
电流输出
<?xml version="1.0" encoding="UTF-8"?>
1234
George Washington lived in a house called Mount Vernon.
Thomas Jefferson lived in a house called Monticello.
期望的输出
<?xml version="1.0" encoding="UTF-8"?>
<DOC><ID>1234</ID>
<TXT>George Washington lived in a house called Mount Vernon.
Thomas Jefferson lived in a house called Monticello.</TXT>
</DOC>
【问题讨论】: