[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: XPath to get node with sons with specific text

Subject: RE: XPath to get node with sons with specific text
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Mon, 10 Aug 2009 12:00:31 +0100
RE:  XPath to get node with sons with specific text
> Contact[contains(Name,'test1')]
> 
> Depending on where ever your context node is.


Or perhaps 

   /List/Contact[starts-with(Name,'test1')]

if starting from the root.

Note that an XPath expression returns a set of nodes - this expression will
return two Contact nodes. It does not return the children of the Contact
nodes directly. But the children are still there - you can navigate from the
selected nodes to their children, their ancestors, or anywhere else. So for
example if in XSLT you do

<xsl:copy-of select="/List/Contact[contains(Name,'test1')]"/>

you will get copies of the subtrees rooted at these Contact nodes.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

> 
> 
>  
> -------Original Message------- 
>  
> From: Andy Kohn
> Date: 8/10/2009 9:34:48 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  XPath to get node with sons with specific text 
>  
> Using XPath, is it possible for me to select a whole branch 
> by Searching for the first child to contain some specific text. 
>  
> For example for the following XML: 
>  
> <List>
> <Contact>
> <Name>test1test</Test>
> <Data>sample data</Data>
> <Data>sample</Data>
> <Data>sample 123</Data>
> </Contact>
> <Contact>
> <Name>test133</Test>
> <Data>sample data</Data>
> </Contact>
> <Contact>
> <Name>test2test</Test>
> <Data>sample data</Data>
> <Data>sample</Data>
> <Data>sample 123</Data>
> </Contact>
> </List> 
>  
> If I search for "test1" I want from the Xpath to return the 
> first <Contact> and the second <Contact>, including all child 
> nodes (<Name> And <Data>): 
>  
> <Contact>
> <Name>test1test</Test>
> <Data>sample data</Data>
> <Data>sample</Data>
> <Data>sample 123</Data>
> </Contact>
> <Contact>
> <Name>test133</Test>
> <Data>sample data</Data>
> </Contact> 
>  
> Something like: 
> //Name[contains(.,'Ab')]
> But this returns only the Name node, and not all the childs. 
>  
> Thanks, 
>  
> Andy. 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.