• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

select one node based on the other node in certain order

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi :

I need help in XSL transformation ,following is my input structure :



I want to create following structure out of it :

I am not sure how to match Pset of T_num with corrosponding T_status ( there order should match , first Pset of T_num should match with first Pset of T_status)
Also this is single snippet example , there are multiple snippets similar like this so when we we select node we have to select all the T_num and T_status after X_number and before another X_number node.

Any help/pointers will be appreciated.

Thanks
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The XPath expression

returns a list of Pset elements which have "T_num" as their "name" attribute. You can make a similar list for "T_status". Those lists should have the same length? Anyway you can then use <xsl:for-each> to process the first list and inside that loop, get the corresponding element from the second list using the position() function.
 
Nicky Jones
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul :

Thanks for reply , It will certainly help to resolve this issue , however at the same time as I mentioned in my mail there can be multiple similar snippets like this so want to select T_Num and T_status between

<Pset name="X_number"> and before start of another <Pset name="X_number"> only or in a similar fashion

How I can achieve this ? Any pointer in this direction .

Regards
R
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another ugly problem. The people who designed this XML format should be repeatedly hit on the head with rotting fish carcasses.

You might do something with the previous-sibling axis to find the previous <Pset name="X_number"> for one of your Pset elements. But really the format should be redesigned so that if there's a natural group of Pset elements, they should be enclosed as children of a higher-level element.
 
Nicky Jones
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul :

I understand this format is pretty bad but it is given by third party on which we have dependency and they have used extensively in their code so redesign will not be possible because that will need massive change in their code.
Do you think using axis previous-sibling I can solve this issue , If I use that will it be possible to capture all xml nodes between these two using xpath which you suggested in your reply.
I thought of using xsl:key but that also does not fit in my criteria to choose nodes between X_number and before start of another X_number .
Kindly suggest and give me some more assistance.
Regards
Rick
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

RickyWolf Jones wrote:Do you think using axis previous-sibling I can solve this issue



As I said, you might be able to do that. Obviously I can't promise that you will be able to do it.
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is not as easy in implementing an xsl template as one would think mainly because people may feel frozen up when actually need to write a working prototype template, before refining, to deal with this generically fairly complicated situation. This is how and you can see how things work out in this prototype implementation.

Suppose the block of of all those tags (Pset) is contained in the container tag, say named "container". The template shown here will match that and do all the work.

This prototype will be "T_num" centric in the sense that every Pset with attribute named "T_num" will be outputted. If the number of Pset with name attribute "T_status" is less than that with name attribute of T_num, those Tstatus will be empty. If the number of Pset with name attribute "T_status" is more than that with name attribute of T_num, those Pset will not be outputted and be ignored. And the whole output will also be wrapped in a tag named "container" again (change it to reflex your need).
 
reply
    Bookmark Topic Watch Topic
  • New Topic