Removing a parent element in xml while keeping it's children using xslt

Viewed 5595

I want to transform the following xml,

<pets>
    <Pet>
        <category>
            <id>4</id>
            <name>Lions</name>
        </category>
        <id>9</id>
        <name>Lion 3</name>
        <photoUrls>
            <photoUrl>url1</photoUrl>
            <photoUrl>url2</photoUrl>
        </photoUrls>
        <status>available</status>
        <tags>
            <tag>
                <id>1</id>
                <name>tag3</name>
            </tag>
            <tag>
                <id>2</id>
                <name>tag4</name>
            </tag>
        </tags>
    </Pet>
</pets>

in to this xml format.

<pets>
    <Pet>
        <category>
            <id>4</id>
            <name>Lions</name>
        </category>
        <id>9</id>
        <name>Lion 3</name>
        <photoUrl>url1</photoUrl>
        <photoUrl>url2</photoUrl>
        <status>available</status>
        <tag>
            <id>1</id>
            <name>tag3</name>
        </tag>
        <tag>
            <id>2</id>
            <name>tag4</name>
        </tag>
    </Pet>
</pets>

I tried to write a template as follows, but it removes the parent element with it's children.

<xsl:template match="photoUrls"/>

How can this be done in xslt. Any help is appreciated.

3 Answers
Related