select one node based on the other node in certain order

Here should go questions about transforming XML with XSLT and FOP.
xslguy
Posts: 2
Joined: Tue May 03, 2011 8:42 pm

select one node based on the other node in certain order

Post by xslguy »

Hi :

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

<command>abc</command>
<Pset name="X_number">
<var name="Y_name">A</var>
<var name="Y_num">6</var>
<var name="Z_name">C</var>
</Pset>
<Pset name="T_num">
<var name="T_num">1</var>
</Pset>
<Pset name="T_num">
<var name="T_num">2</var>
</Pset>
<Pset name="T_status">
<var name="T_status">U</var>
</Pset>
<Pset name="T_status">
<var name="T_status">V</var>
</Pset>
<Pset name="end_matching">
</Pset>

<Pset name="Y_number">


I want to create following structure out of it :
<Event >

<Tnum>1</Tnum> (here TNum corresponds to first Pset of T_Num and get the value from <var name="T_num">2</var>)

<Tstatus>U</Tstatus> (here Tstatus corresponds to first Pset of T_status and get the value from <var name="T_Status">U</var>)

<Tnum>2</Tnum> ( Here also it is second one , and there can be multiple )
<Tstatus>V</Tstatus>

<Event>

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 Y_number.

Any help/pointers will be appreciated.

Thanks
adrian
Posts: 2879
Joined: Tue May 17, 2005 4:01 pm

Re: select one node based on the other node in certain order

Post by adrian »

Hello,

Given the result you presented as example, you can try something like this:

Code: Select all

<xsl:template match="/">
<Event>
<xsl:for-each select="//Pset[@name='T_num']">
<xsl:variable name="pos" select="position()"/>
<Tnum><xsl:value-of select="var[@name='T_num']"/></Tnum>
<Tstatus><xsl:value-of select="//Pset[@name='T_status'][position()=$pos]/var[@name='T_status']"/></Tstatus>
</xsl:for-each>
</Event>
</xsl:template>
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
xslguy
Posts: 2
Joined: Tue May 03, 2011 8:42 pm

Re: select one node based on the other node in certain order

Post by xslguy »

Thanks for the reply , It will help to solve the issue some extent ,but actual issue is to select all the T_num and T_status after X_number and before Y_number(You can consider it as X_number to make it simple).
This X_number attributes appears multiple times in xml and I have to select all the T_num and T_status after this and before starting of another X_number.
I hope I am clear in explaining the issue.
Post Reply