Connecting Tech Pros Worldwide Help | Site Map

XSLT match text then following sibling

Newbie
 
Join Date: Apr 2009
Location: Dallas/Fort Worth Texas
Posts: 8
#1: Apr 1 '09
Hi Everyone,

I have the following XML:

Expand|Select|Wrap|Line Numbers
  1. <input type ="Data">
  2.       <parameter name ="Name">
  3.              <variable type="Static">
  4.                     <![CDATA[site]]>
  5.              </variable>
  6.       </parameter>
  7.       <parameter name="Value">
  8.              <variable type="Static">
  9.                     <![CDATA[joe]]>
  10.              </variable>
  11.       </parameter>
  12. </input>
I need to match the variable text(site) and grab the variable text(joe). I am not sure how to use the "following-sibling" syntax in this example.

Thanks in advance,

Todd
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#2: Apr 2 '09

re: XSLT match text then following sibling


Quote:

Originally Posted by tgow View Post

I need to match the variable text(site) and grab the variable text(joe).

could you elaborate? I do not understand the requirement.

if you want to match text(joe) from text(site) it would be
Expand|Select|Wrap|Line Numbers
  1. ancestor::parameter/following-sibling::parameter/variable
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#3: Apr 2 '09

re: XSLT match text then following sibling


??
Expand|Select|Wrap|Line Numbers
  1. <xsl:variable name="name" select="'site'"/>
  2. <xsl:value-of select="//input[parameter[@name = 'Name'] = $name]/parameter[@name='Value']"/>
  3.  
Newbie
 
Join Date: Apr 2009
Location: Dallas/Fort Worth Texas
Posts: 8
#4: Apr 2 '09

re: XSLT match text then following sibling


I have a large XML files that repeats the following XML:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <script>
  3.   <action>
  4.     <actions>
  5.      <postdata>
  6.         <input type="Data">
  7.             <parameter name="Name">
  8.                <variable type="Static">
  9.                   <![CDATA[trans]]>
  10.                </variable>
  11.             <parameter name="Value">
  12.                 <variable type="Static">
  13.                   <![CDATA[hello]]>
  14.             </variable>
  15.         </input>
  16.         <input type="Data">
  17.             <parameter name="Name">
  18.                <variable type="Static">
  19.                   <![CDATA[site]]>
  20.                </variable>
  21.             <parameter name="Value">
  22.                 <variable type="Static">
  23.                   <![CDATA[joe]]>
  24.             </variable>
  25.         </input>
  26.  
  27. ......
  28.  
I have written the following xsl which pulls it but the XPATH is hardcoded:

Expand|Select|Wrap|Line Numbers
  1. <xsl:value-of select="//script/actions/action/postdata/input[@type = 'Data'][2]/parameter[@name = 'Value']"</xsl:value-of>
  2.  
Each XML file is the same but the "<input></input>" order could be different so I really need the "<parameter name="Value"> CDATA value which is "joe" but this will be different every time. I was trying to look for the "<parameter name="Name">" CDATA value which is "site" because this is consistent and grab the "following::sibling" possibly.

I hope this makes more sense.

Thanks again,

Todd
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#5: Apr 3 '09

re: XSLT match text then following sibling


replace the [2] with
[parameter[@name = 'Name'] = 'site']
Newbie
 
Join Date: Apr 2009
Location: Dallas/Fort Worth Texas
Posts: 8
#6: Apr 13 '09

re: XSLT match text then following sibling


Thanks for the reply. This gets me closer but it is just a Boolean true/false. What I would like to do in pseudo-code is if the following:

if (site = true) exists
then
grab the following-sibling value (joe)

Do I need to use a variable for this or the choose logic?

Thanks in advance,

Todd
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#7: Apr 14 '09

re: XSLT match text then following sibling


? If you already know the value is joe, why bother grabbing it?
Newbie
 
Join Date: Apr 2009
Location: Dallas/Fort Worth Texas
Posts: 8
#8: Apr 14 '09

re: XSLT match text then following sibling


The value of "joe" is dynamic. The value of "site" is static. If I find "site" the I need the following sibling which is the value of "joe" in my example but it could be anything.

Thanks again,

Todd
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#9: Apr 14 '09

re: XSLT match text then following sibling


I don't understand what was wrong with the solution:
Expand|Select|Wrap|Line Numbers
  1. <xsl:value-of select="//script/actions/action/postdata/input[@type = 'Data'][parameter[@name = 'Name'] = 'site']/parameter[@name = 'Value']"/>
  2.  
Newbie
 
Join Date: Apr 2009
Location: Dallas/Fort Worth Texas
Posts: 8
#10: Apr 15 '09

re: XSLT match text then following sibling


It works..thanks for you help.

Just an issue between the chair and the keyboard. ;^)

Thanks again,

Todd
Reply