473,390 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

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 6150
Dormilich
8,658 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

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

Similar topics

4
by: Richard Rudie | last post by:
Have any other Windows iTunes users looked at the XML file iTunes uses as its database? (Does iTunes for Mac use an XML file, too?) When I noticed that it was XML, I thought it might be useful, or...
3
by: bjam | last post by:
Hi, I am hoping someone can help with this I am assuming it is pretty basic but I don't see anything that jumps out at me at how to do this. Is there a way to have all the items output from the...
6
by: Bloody Viking | last post by:
Namaste, Y'all. Given an element A containing elements B,C,D,E,F, I need to create a variable that gets the value of element C, conditionally followed by the value of element D, only if the...
1
by: Juho Jussila | last post by:
Hi How can I easily ensure that Xml document has elements in certain order? I think it can be done with Xml schema, but I'd like to use Xslt, because the validation is a part of Xslt...
1
by: Patrick.O.Ige | last post by:
I have a xml file and i want to format it using XSL My XSL file and XML below I needed to do a distinct which is ok on the first node "Code" For the "programDescription" i did below which gets the...
8
by: Hercules Dev. | last post by:
Hi all, I'm new in xslt and xpath, so my question might be simple but i'm learning. I have an XML document and need to transform it into another XML, I use xslt and it works, but there is a...
10
by: olivier.scalbert | last post by:
Hello, the following constraints: source: <Source> <Item>AAA</Item> <Item>BBBBBBBBBBB</Item> <Item>CCCCCCCCC</Item> <Item>DDDDDDDDDDDDDDD</Item>
2
jkmyoung
by: jkmyoung | last post by:
Here's a short list of useful xslt general tricks that aren't taught at w3schools. Attribute Value Template Official W3C explanation and example This is when you want to put dynamic values...
4
by: MRe | last post by:
Hi, Is it possible using XSLT to transform this.. <test> <b>0</b> <a>1</a> <a>2</a> <b>3</b> <b>4</b>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.