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 March 28th, 2007, 08:37 AM
Authorized User
 
Join Date: Nov 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Some XPath functions not available

Apologies if this is slightly OT...I guessed that XPath knowledge is mostly likely to be found in this forum.

I'm using XPath to locate elements in JavaScript (incidentally its a techinque I highly recommend, makes things much easier) I would like to match a div element that looks like any one of these:

Code:
<div class="modifiers toolbar">
Code:
<div class="toolbar modifiers">
Code:
<div class="modifiers toolbar ">
Code:
<div class="  toolbar  modifiers    ">
At the moment I'm just doing this:

Code:
.//div[contains(@class, "modifiers") and contains(@class, "toolbar")]
but obviously this is going to match...
Code:
<div class="footoolbar barmodifiers">
...too. I see from http://www.w3schools.com/xpath/xpath...ons.asp#string that I should be able to use translate() or match() functions but those don't seem to be available. Can anyone provide an explanation as to why that is / how I could achieve this? The JavaScript call (mostly) responsible for using XPath within JS is this:
Code:
document.createExpression()
Many thanks.

 
Old March 28th, 2007, 08:47 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

translate and matches are XPath functions although the later is version 2.0 and no HTML XSLT engine supports version 2.0 as far as I know. Can you point to some documentation that explains document.createExpression() as I've not come across this?

--

Joe (Microsoft MVP - XML)
 
Old March 28th, 2007, 09:13 AM
Authorized User
 
Join Date: Nov 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Can you point to some documentation that explains document.createExpression() as I've not come across this
In short....no :( This http://jmvidal.cse.sc.edu/talks/java.../allslides.xml explains how to do it but not what its capable of.

...some time later..

I've done some hunting and this http://www.w3.org/TR/2004/NOTE-DOM-L...Path-20040226/ might be more what we're after. But there's no knowing how much this relates to the actual FireFox implementation. IE is, of course, another story. XPath in IE is achieved simply with this:
Code:
someDomContext.selectNode(xPathStr)
 
Old March 28th, 2007, 02:22 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

translate() should be available but it isn't very useful for what you want to do. Perhaps you meant tokenize(). tokenize() and matches() are XPath 2.0 functions and if they aren't available it means you are using one of the many XPath processors that don't yet support XPath 2.0.

I'd suggest using concat() to add a space at each end of the string and then using contains($x, ' modifiers ').

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 29th, 2007, 05:25 AM
Authorized User
 
Join Date: Nov 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes sorry, I did mean tokenize(). Thanks for the suggestion I might do that.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Xpath functions aldwinenriquez XML 4 August 25th, 2008 03:27 AM
Xpath help please rishid XML 1 February 28th, 2007 03:23 AM
Using Xpath functions Tomi XSLT 1 July 21st, 2006 05:43 AM
XPath: String functions question. pupu79 XSLT 4 January 10th, 2005 03:00 PM
help with XPath kend XSLT 2 July 15th, 2003 01:14 PM





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