Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get attribute values of repetitive nodes from an XML

 
Balagopal Kannampallil
Ranch Hand
Posts: 136
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your context node is the <service> element, right? Then the XPath expression for the "index" attribute is simply "@index".
 
Balagopal Kannampallil
Ranch Hand
Posts: 136
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic