Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   Select nodes where an attribute contains some sub-text (http://www.velocityreviews.com/forums/t170530-select-nodes-where-an-attribute-contains-some-sub-text.html)

Duncan 02-09-2006 03:59 PM

Select nodes where an attribute contains some sub-text
 
Can I use the contains() function within an xpath query to return a
node whose attribute contains some text?

Something like: selectNodes("//Dataset[@Pattern contains(@Pattern,
'xyz')]

so for the given xml doc

<root>
<Datasets>
<Dataset name="dataset1" Pattern="abc" AnotherAttribute="xyz"/>
<Dataset name="dataset2" Pattern="xyz" AnotherAttribute="xyz"/>
<Dataset name="dataset3" Pattern="vwxyz"/>
</Datasets>
</root>

The nodes dataset2 and dataset3 would be returned because their
'Pattern' attribute contains the text 'xyz'.

Many thanks,

Duncan.


Martin Honnen 02-09-2006 04:10 PM

Re: Select nodes where an attribute contains some sub-text
 


Duncan wrote:

> Can I use the contains() function within an xpath query to return a
> node whose attribute contains some text?


Yes.


> Something like: selectNodes("//Dataset[@Pattern contains(@Pattern,
> 'xyz')]


That is syntactically wrong. A possible XPath expression could be
/root/Datasets/Dataset[contains(@Pattern, 'xyz')]


--

Martin Honnen
http://JavaScript.FAQTs.com/

Duncan 02-09-2006 04:46 PM

Re: Select nodes where an attribute contains some sub-text
 
By jove, it works!

Thanks,

Duncan.



All times are GMT. The time now is 02:07 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.