469,330 Members | 1,284 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

XSLT match text then following sibling

8
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
Apr 1 '09 #1
9 6005
Dormilich
8,651 Expert Mod 8TB
@tgow
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
Apr 2 '09 #2
jkmyoung
2,057 Expert 2GB
??
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.  
Apr 2 '09 #3
tgow
8
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
Apr 2 '09 #4
jkmyoung
2,057 Expert 2GB
replace the [2] with
[parameter[@name = 'Name'] = 'site']
Apr 3 '09 #5
tgow
8
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
Apr 13 '09 #6
jkmyoung
2,057 Expert 2GB
? If you already know the value is joe, why bother grabbing it?
Apr 14 '09 #7
tgow
8
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
Apr 14 '09 #8
jkmyoung
2,057 Expert 2GB
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.  
Apr 14 '09 #9
tgow
8
It works..thanks for you help.

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

Thanks again,

Todd
Apr 15 '09 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Richard Rudie | last post: by
6 posts views Thread by Bloody Viking | last post: by
1 post views Thread by Juho Jussila | last post: by
8 posts views Thread by Hercules Dev. | last post: by
10 posts views Thread by olivier.scalbert | last post: by
4 posts views Thread by MRe | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.