0
votes

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?

1
This should be really easy. Please try it first by yourself.hr_117
SHould I separately declare 4 'A' tags like this <xsl:template match="A[0]"> ??? for A[1],A[2] etc ???quad
Have a look for xslt i dentity transform (e.g. en.wikipedia.org/wiki/Identity_transform#Using_XSLT) and add a match for B without xsl:copy (only applay-templates).hr_117

1 Answers

0
votes

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>