Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 19th, 2015, 12:16 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #2 (permalink)  
Old March 19th, 2015, 12:31 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,133
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?
Reply With Quote
The Following User Says Thank You to samjudson For This Useful Post:
mdel (March 19th, 2015)
  #3 (permalink)  
Old March 19th, 2015, 12:38 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 12:32 PM
Service Starts and Stops rodmcleay .NET Web Services 1 January 30th, 2006 03:30 AM
Application starts again sarvesh189 Forum and Wrox.com Feedback 2 May 25th, 2005 02:07 AM



All times are GMT -4. The time now is 08:32 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.