Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT: add an attribute

Reply
Thread Tools

XSLT: add an attribute

 
 
Jeff Higgins
Guest
Posts: n/a
 
      05-12-2006
Hi,

How can I add an attribute to selected elements?

For each section element in the source document,
I would like to add a name attribute where the attribute is equal to:
<xsl:number level="multiple" count="section" format="1_1"/>

For source document:

<src>
<section>
<section>
<section/>
<section/>
<section/>
</section>
</section>
</src>

The result document would be:

<src>
<section name="1">
<section name="1_1">
<section name="1_1_1"/>
<section name="1_1_2"/>
<section name="1_1_3"/>
</section>
</section>
</src>

Thanks,
Jeff Higgins


 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      05-12-2006
Start with the identity stylesheet, then add something like:

<xsl:template match="section">
<xsl:copy>
<xsl:attribute name="name">
<xsl:number level="multiple" count="section"
format="1_1"/></xsl:attribute>
<xsl:apply-templates select="@*|*"/>
</xsl:copy>
</xsl:template>


In other words: Copy the <section>, add the attribute, then recursively
process the other attributes and children.
 
Reply With Quote
 
 
 
 
Jeff Higgins
Guest
Posts: n/a
 
      05-13-2006
Thanks Joe.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validation (XHTML 1.0 Transitional): Attribute 'leftmargin' is not a valid attribute of element 'body'. anonymous ASP .Net 1 08-02-2006 08:05 AM
picking value of one attribute based on a child elements attribute? XPath? vjethava@gmail.com XML 2 03-06-2006 05:19 AM
Implied instance attribute creation when referencing a class attribute Russell Warren Python 5 01-17-2006 05:07 AM
XSLT: Making attribute to parent attribute Bostonasian XML 1 09-18-2005 07:30 AM
class attribute to instance attribute Donnal Walter Python 4 07-06-2005 04:35 AM



Advertisments