Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML 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 March 19th, 2015, 12:16 PM
Registered User
 
Join Date: Mar 2015
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default xpath starts-with issue

Hello. I've been trying to find a workaround on the following problem:

given the following xml

HTML Code:
<root>
	<lemma>
		<terms>
			<en>en_term1</en>
			<gr>gr_term1</gr>
		</terms>
	</lemma>
	<lemma>
		<terms>
			<en>en_term2</en>
			<gr>tgr_term1a</gr>
			<gr>gr_term2a</gr>
		</terms>
	</lemma>
	<lemma>
		<terms>
			<en>en_term3</en>
			<gr>gr_term1b</gr>
		</terms>
	</lemma>
</root>
i run the following xpath:

//lemma[starts-with(terms/gr,'gr')]

which returns the first and last <lemma> but not the middle one which contains a <gr> that starts with 'gr'. So my question is how can i "search" all <gr> elements within a <terms>?

Thanks in advance
 
Old March 19th, 2015, 12:31 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I'm assuming this is XSLT 1?

If I remember correctly in XSLT 1 a function like starts-with only takes a single value, not a sequence, so terms/gr is equivalent to terms/gr[1], i.e. the first gr element only.

Try something like this:

Code:
//lemma[terms/gr[starts-with(., 'gr')]]
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
mdel (March 19th, 2015)
 
Old March 19th, 2015, 12:38 PM
Registered User
 
Join Date: Mar 2015
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by samjudson View Post
I'm assuming this is XSLT 1?

If I remember correctly in XSLT 1 a function like starts-with only takes a single value, not a sequence, so terms/gr is equivalent to terms/gr[1], i.e. the first gr element only.

Try something like this:

Code:
//lemma[terms/gr[starts-with(., 'gr')]]
yep, that worked.... thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Cross Browser XPath Issue crazy BOOK: Professional JavaScript for Web Developers 2nd edition ISBN: 9780470227800 1 September 18th, 2010 08:54 PM
XSL/XPATH namespace issue caltech XSLT 2 April 26th, 2010 11:31 AM
Tomcat suddenly stops after starts annumol Apache Tomcat 2 February 9th, 2008 01:32 PM
Service Starts and Stops rodmcleay .NET Web Services 1 January 30th, 2006 04:30 AM
Application starts again sarvesh189 Forum and Wrox.com Feedback 2 May 25th, 2005 02:07 AM





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