• Post Reply Bookmark Topic Watch Topic
  • New Topic

XPATH and concat curiosity  RSS feed

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have an xml viz.
<element>
<component>....</component>
<event>....</event>
<event>....</event>
<event>....</event>
<event>....</event>
</element>

The number of events will be dynamic.
For a relevant component,we need to return the cooresponding events pipe-delimited.
We arrive at the particular component through SelectNodes - is there a smart,concide XPATH expression which can allow me to return the set of events in the way we want,rather than recursing through the set.
Note that component and event nodes are parent(ed) by 'element'.
We are using javascript.
 
Sheriff
Posts: 22951
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure that I understand this. The XPath expression to identify those nodes is just "/element/component/event". Of course that won't give you the contents of the nodes, concatenated, with pipes delimiting the data, but XPath doesn't do that sort of thing anyway. You would have to do that in your Javascript code, but you wouldn't need recursion.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming you need this using xslt, use keys as below:

Define a key
<xsl:key name="EventKey" match="/element/event" use="../component"/>

Now use the key to get the event nodes using component
key('EventKey','WhatEverThecomponent') returns all the event nodes

vinay
(vinay.l@tcs.com)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!