简体   繁体   中英

Transforming xml to xml using XSLT

I am very much beginner in XSLT. I am trying to transform this XML :

<A>
    <B>
        <C>
            <A id="1">
                <I/><T/>
            </A>
            <A id="2">
                <I/><T/>
            </A>
        </C>
        <C>
            <A id="3">
                <I/><T/>
            </A>
            <A id="4">
                <I/> <T/>
            </A>
        </C>
    </B>
</A>

to something like :

<A>
    <B>  
        <A id="1">
            <I/> <T/> 
        </A>
        <A id="2"/> 
            <I/> </T> 
        </A>
        <A id="3">
            <I/> <T/> 
        </A>
        <A id="4"/> 
            <I/> <T/> 
        </A>
    </B> 
</A>  

As you can see here I have 2 'C' tag blocks under 'B' tag block. I want get rid of the 'C' tag and add all sub 'A' tags under 'B' tag and also I need 'I' and 'T' tags within 'A'..

Could someone please help me on this one?

It is as Ian says:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

    <xsl:template match="C">
        <xsl:apply-templates/>
    </xsl:template>

</xsl:stylesheet>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM