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.
sri1209Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
You need to add
<xsl:copy-of select="@*"/>
After the xsl:copy tag
In order to copy all the attributes
0
sri1209Author Commented:
Thank you for the very quick response geert, will try it out
0
Geert BormansInformation ArchitectCommented:
Very good understanding by the way that you made the template match selective (that is a real XSLT way of thinking :-)

I was on an iPad earlier having limited editing capabilities
but here is the full template, just to be sure I was clear enough

    <xsl:template match="L1/Captions/Caption[@id ='A']">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <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>   

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sri1209Author Commented:
Thank you :), and always it works superbly.
0
Geert BormansInformation ArchitectCommented:
welcome
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.