0

I am new to the XSL transformations. Where i am trying to extract a part of XML using XSLT.

The Source XML

<tree>
    <trunk>
        <branch>
            <leaves></leaves>
            <flowers></flowers>
            <fruits></fruits>
        </branch>
    </trunk>
</tree>

and i am expecting the following XML as output

<root>    
    <branch>
        <leaves></leaves>
        <flowers></flowers>
        <fruits></fruits>
    </branch>
</root>

Please provide the transformation, i have been doing some random stuff for long time.

2 Answers 2

5
  <xsl:template match="/tree/trunk/branch">
    <root>
      <xsl:copy-of select="."/>
    </root>
  </xsl:template>
Sign up to request clarification or add additional context in comments.

Comments

2

Something like the following

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

<xsl:template match="/*">
    <xsl:element name="root">
        <xsl:for-each  select="//branch">
            <xsl:element name="branch">
                <xsl:for-each select="*">
                    <xsl:copy-of select="."/>
                </xsl:for-each>
            </xsl:element>
        </xsl:for-each>
    </xsl:element>
</xsl:template>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.