aspose file tools*
The moose likes XML and Related Technologies and the fly likes select one node based on the other node in certain order 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 "select one node based on the other node in certain order" Watch "select one node based on the other node in certain order" New topic
Author

select one node based on the other node in certain order

Nicky Jones
Greenhorn

Joined: May 03, 2011
Posts: 14
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
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

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

Joined: May 03, 2011
Posts: 14
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
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

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

Joined: May 03, 2011
Posts: 14
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
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

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.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 547
    
    3
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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: select one node based on the other node in certain order