how to ignore builtin xslt rules

时间:2017-11-13 06:33:24

标签: xml xslt

I have this xml:

<?xml version="1.0" encoding="UTF-8"?>
<lib>
    <books xmlns="http://www.books.com/SRK">
        <name>English</name>
    </books>
    <cats>
        <cat>cat1</cat>
        <cat>cat2</cat>
    </cats>
</lib>

and this xslt:

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

    <xsl:template match="//cats/*">        
        <xsl:element name="{local-name()}">
            <xsl:apply-templates select="node()"/>
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>

the expected out is to not have english in output but first it write english and then what I need. I mean currently output is :

English<cat>cat1</cat>
<cat>cat2</cat>

but I don't want it contain English.

1 个答案:

答案 0 :(得分:0)

您只能将模板应用于cats部分。像这样:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes"/>    
    <xsl:template match="node()|@*">                       
           <xsl:apply-templates select="//cats"/>                  
    </xsl:template>    
    <xsl:template match="cats">
        <xsl:copy-of select="."/>
    </xsl:template>    
</xsl:stylesheet>