如何使用 XSLT 注释掉特定元素
HOW TO COMMENT OUT PARTICULAR ELEMENT USING XSLT
如何仅使用 XSLT 取消对特定元素 'navref' 的注释,有人可以研究一下并提出建议吗?
XML 输入:
<?xml version="1.0" encoding="UTF-8"?>
<topicgroup collection-type="sequence">
<!--Handling topicref with navref-->
<topicref collection-type="sequence" id="107746"
href="../../../../../../Section_General_Notes/107746.dita">
<topicmeta>
<navtitle/>
<critdates>
<created date="09-Apr-2009" golive="01-Jul-2009" expiry=""/>
</critdates>
<data name="section_num" value="55"/>
</topicmeta>
</topicref>
<!--<navref mapref="../../../../../../Section_General_Notes/107746.ditamap"/>-->
</topicgroup>
预期输出:
<?xml version="1.0" encoding="UTF-8"?>
<topicgroup collection-type="sequence">
<!--Handling topicref with navref-->
<topicref collection-type="sequence" id="107746"
href="../../../../../../FASB_Section_General_Notes/107746.dita">
<topicmeta>
<navtitle/>
<critdates>
<created date="09-Apr-2009" golive="01-Jul-2009" expiry=""/>
</critdates>
<data name="section_num" value="55"/>
</topicmeta>
</topicref>
<navref mapref="../../../../../../Section_General_Notes/107746.ditamap"/>
</topicgroup>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="comment()" priority="1">
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
而不是:
<xsl:template match="comment()" priority="1">
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:template>
尝试:
<xsl:template match="comment()[starts-with(., '<navref')]" >
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:template>
如何仅使用 XSLT 取消对特定元素 'navref' 的注释,有人可以研究一下并提出建议吗?
XML 输入:
<?xml version="1.0" encoding="UTF-8"?>
<topicgroup collection-type="sequence">
<!--Handling topicref with navref-->
<topicref collection-type="sequence" id="107746"
href="../../../../../../Section_General_Notes/107746.dita">
<topicmeta>
<navtitle/>
<critdates>
<created date="09-Apr-2009" golive="01-Jul-2009" expiry=""/>
</critdates>
<data name="section_num" value="55"/>
</topicmeta>
</topicref>
<!--<navref mapref="../../../../../../Section_General_Notes/107746.ditamap"/>-->
</topicgroup>
预期输出:
<?xml version="1.0" encoding="UTF-8"?>
<topicgroup collection-type="sequence">
<!--Handling topicref with navref-->
<topicref collection-type="sequence" id="107746"
href="../../../../../../FASB_Section_General_Notes/107746.dita">
<topicmeta>
<navtitle/>
<critdates>
<created date="09-Apr-2009" golive="01-Jul-2009" expiry=""/>
</critdates>
<data name="section_num" value="55"/>
</topicmeta>
</topicref>
<navref mapref="../../../../../../Section_General_Notes/107746.ditamap"/>
</topicgroup>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="comment()" priority="1">
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
而不是:
<xsl:template match="comment()" priority="1">
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:template>
尝试:
<xsl:template match="comment()[starts-with(., '<navref')]" >
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:template>