Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 4th, 2009, 03:15 PM
Registered User
 
Join Date: Aug 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Searching text within a node

I have a block of xml that looks like the following.

<Form>
<Names>
<LastName>Jones</LastName>
<LastName>Smith</LastName>
<LastName>Anderson</LastName>
</Names>
</form>


I need to display blocks of code only if text matches the text in any of the three nodes(or more) in LastName. So you may have a block of code that should display only if "Jones" is in the above nodes. I've examined XSL IF and Choose and can't really find anything that works for this purpose. Thanks.
 
Old August 4th, 2009, 03:37 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The condition test="LastName='Jones'" does exactly what you are looking for - it returns true if any of the children named LastName has the string value "Jones".
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old August 4th, 2009, 03:38 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

By the way, it's generally considered antisocial to ask the same question in more than once place at the same time. It's like asking both your neighbours if you can borrow some sugar.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old August 6th, 2009, 09:07 AM
Registered User
 
Join Date: Aug 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thanks

Keep in mind that beginners often struggle with syntax so I had to rely on a response from the other list to figure this out. This was my answer in the short form.

<xsl:if test="'Smith'=Form/Names/LastName">





Similar Threads
Thread Thread Starter Forum Replies Last Post
searching a text file for repeated numbers Un33k Visual Basic 2005 Basics 1 October 30th, 2007 01:50 PM
Searching an expression in a text file. rachellim C# 2005 1 January 15th, 2007 11:18 AM
How to select a node or text from treeview MacDevv C# 2005 3 September 5th, 2006 05:23 AM
highlighting the text after searching shazia1 VS.NET 2002/2003 0 April 1st, 2006 04:37 PM
Searching for a carriage return in a text field levinll SQL Language 3 March 10th, 2004 04:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.