使用XSLT删除双引号

时间:2019-04-01 10:47:42

标签: xml xslt

如果在元素<remove>some text</remove>之后直接加上双引号,则必须删除双引号。例如

  

这将被解释为“关于动词”   与某些“植物”相对应   在

上      

应该是

     

这将以动词相关解释   还有一些植物等等

<p>This is to be interpreted in "<remove>about verb</remove>" accordance with something "<remove>some of plants</remove>" and so on</p>

应该是

<p>This is to be interpreted in <remove>about verb</remove> accordance with something <remove>some of plants</remove> and so on</p>

2 个答案:

答案 0 :(得分:3)

XSLT 1.0 中,可以通过以下方式处理:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="text()">
    <xsl:variable name="s" select="preceding-sibling::node()[1][self::remove] and starts-with(., '&quot;')"/>
    <xsl:variable name="e" select="following-sibling::node()[1][self::remove] and substring(., string-length(.))='&quot;'"/>
    <xsl:value-of select="substring(., 1 + $s, string-length(.) -$s -$e)"/>
</xsl:template>

</xsl:stylesheet>

答案 1 :(得分:-1)

对于2.0,您可以使用fn:replace():

replace(//p,'&quot;','')