如何删除xml中的注释而不删除xslt中的文本

如何删除xml中的注释而不删除xslt中的文本,xml,xslt,xslt-2.0,Xml,Xslt,Xslt 2.0,输入文件 <a> <b> <!--<docinfo:topiccodes><docinfo:topiccode>#PA#HKCRP#</docinfo:topiccode> <docinfo:topiccode>#PA#HKCRPM#</docinfo:topiccode><docinfo:topiccode>#PA#HKDIS#</docinfo:topiccode><

输入文件

<a>
<b>
<!--<docinfo:topiccodes><docinfo:topiccode>#PA#HKCRP#</docinfo:topiccode>    <docinfo:topiccode>#PA#HKCRPM#</docinfo:topiccode><docinfo:topiccode>#PA#HKDIS#</docinfo:topiccode><docinfo:topiccode>#PA#HKDISM#</docinfo:topiccode><docinfo:topiccode>#PA#CODE#</docinfo:topiccode></docinfo:topiccodes>--> 
</b>
</a>

输出扩展

<a>
<b>
<docinfo:topiccodes><docinfo:topiccode>#PA#HKCRP#</docinfo:topiccode>    <docinfo:topiccode>#PA#HKCRPM#</docinfo:topiccode><docinfo:topiccode>#PA#HKDIS#</docinfo:topiccode><docinfo:topiccode>#PA#HKDISM#</docinfo:topiccode><docinfo:topiccode>#PA#CODE#</docinfo:topiccode></docinfo:topiccodes> 
</b>
</a>

#PA#HKCRP#PA#HKCRPM#PA#HKDIS#PA#HKDISM#PA#代码#
xslt编写

<xsl:template match="comment()">
<xsl:value-of select="."/>
</xsl:template>

试试这个:

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

    <xsl:strip-space elements="*"/>
    <xsl:output indent="yes" omit-xml-declaration="yes"/>

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

    <xsl:template match="comment()">
        <xsl:value-of select="." disable-output-escaping="yes"></xsl:value-of>
    </xsl:template>

</xsl:stylesheet>


不起作用..我试过了,但对我不起作用。我不知道你是如何实现的。但它正在发挥作用。请看这里()好的,我在我的代码中实现了它,我认为我的代码有任何问题,换句话说,它工作正常。