Link to home
Start Free TrialLog in
Avatar of tesmc
tesmcFlag for United States of America

asked on

XSL: adding attribute to a node

I have code that

<ServicesGroup>
      <xsl:apply-templates select="Other/Services"/>
</ServicesGroup>
                        
            

<xsl:template match="Services">
      <xsl:for-each select="Service">
             <xsl:copy-of select="current()"/>
      </xsl:for-each>
</xsl:template>

with the following input
<Services>
      <Service Method="D" Type="F" Code="A" Type="Surcharge">
                  .......
      </Service>
</Services>

So far, it only copies the input and returns it back. But I want it to add an attribute @Status="CONFIRMED" AND copy the rest of the <Service> node. Such that:
<Services>
      <Service Method="D" Type="F" Code="A"  Status="CONFIRMED">
                  .......
      </Service>
</Services>

How can I copy the contents of entire Service node and add that new attribute before exiting the template?
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tesmc

ASKER

can u please explain what   <xsl:copy-of select="@* | node()"/> does?

is the pipe to concatenate ? and node() ?
copy of
all the attributes (@*)
and all (| is the union operator)
the child nodes (node())

node() = * | comment() | process-instruction() | text()
Avatar of tesmc

ASKER

thanks for ur help. it worked.