aspose file tools*
The moose likes XML and Related Technologies and the fly likes How to get attribute values of repetitive nodes from an XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to get attribute values of repetitive nodes from an XML" Watch "How to get attribute values of repetitive nodes from an XML" New topic
Author

How to get attribute values of repetitive nodes from an XML

Balagopal Kannampallil
Ranch Hand

Joined: Oct 18, 2004
Posts: 136

Hi,

I have an XML file like


and I have an XSL file like

How can I replace the ??? in the xsl file to print the index attribute of each service tag ie '123' and '456' each time a service tag is encountered.


SCJP 5.0 and now fighting with ExtJS
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18909
    
    8

Your context node is the <service> element, right? Then the XPath expression for the "index" attribute is simply "@index".
Balagopal Kannampallil
Ranch Hand

Joined: Oct 18, 2004
Posts: 136

So if I write something like this . It always prints '123' without considering the index attribute of the next service element. How can we print the other index attributes if there are more than one service elements?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18909
    
    8

So, "/support/service/@index" is a nodeset consisting of all the "index" elements you're looking for. The xsl:value-of element takes the first of these.

You might consider reading what I wrote in my earlier response.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get attribute values of repetitive nodes from an XML