sri1209
asked on
add a tag to xml with xsl
Hi, i have the below xml
<L1>
<Captions>
<Caption id="A">
<b>Income</b>
</Caption>
<Caption id="B">
<b>Month:</b>
</Caption>
</Captions>
</L1>
i am trying to get the xml as below (get the tag <body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"> </body> around Caption id="A" )
<L1>
<Captions>
<Caption id="A">
<body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<b>Income</b></body>
</Caption>
<Caption id="B">
<b>Month:</b>
</Caption>
</Captions>
</L1>
the xsl i am using is
<xsl:template match="L1/Captions/Caption [@id ='A']">
<xsl:copy>
<body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<xsl:apply-templates select="node()"/>
</body>
</xsl:copy>
</xsl:template>
but its removing the id="A" inside the <caption>
its getting the xml as below
<L1>
<Captions>
<Caption>
<body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"><b>Income</b> </body>
</Caption>
<Caption id="B">
<b>Month:</b>
</Caption>
</Captions>
</L1>
can the experts correct me where i am going wrong..?
Thanks in advance.
<L1>
<Captions>
<Caption id="A">
<b>Income</b>
</Caption>
<Caption id="B">
<b>Month:</b>
</Caption>
</Captions>
</L1>
i am trying to get the xml as below (get the tag <body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"> </body> around Caption id="A" )
<L1>
<Captions>
<Caption id="A">
<body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<b>Income</b></body>
</Caption>
<Caption id="B">
<b>Month:</b>
</Caption>
</Captions>
</L1>
the xsl i am using is
<xsl:template match="L1/Captions/Caption
<xsl:copy>
<body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<xsl:apply-templates select="node()"/>
</body>
</xsl:copy>
</xsl:template>
but its removing the id="A" inside the <caption>
its getting the xml as below
<L1>
<Captions>
<Caption>
<body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"><b>Income</b>
</Caption>
<Caption id="B">
<b>Month:</b>
</Caption>
</Captions>
</L1>
can the experts correct me where i am going wrong..?
Thanks in advance.
ASKER
Thank you for the very quick response geert, will try it out
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you :), and always it works superbly.
welcome
<xsl:copy-of select="@*"/>
After the xsl:copy tag
In order to copy all the attributes