 |
| 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
|
|
|
|

February 8th, 2008, 09:25 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
|
|
TRANSLATE FUNCTION INSIDE XPATH
Hi,
I am experiencing a strange error in IE 6.0 when I run an XPATH expression with the translate function inside it.
In Firefox the code works fine but IE is throwing an error. I would appreciate if anyone could point me in the right direction about how to fix this.
I have to use the translate function to remove the hyphen "-" from the @date values - <Issue date="2008-01-01"> - so that I can do a >= or <= comparison with the dates passed in (20080101 - 20080301)
This is the XPTAH Expression:
numFromVal = 20080101
numToVal = 20080301
"Media/Vehicle/RateCards/RateCard[@id = '" + ratecardId + "' and @name = '" + ratecardName + "']/Ads/Ad/Issues/Issue[translate(@date,'-','')>=" + numFromVal + " and translate(@date,'-','')<=" + numToVal + "]/Insertion[@ordered]"
"Media/Vehicle/RateCards/RateCard[@id = '2547' and @name = '2008']/Ads/Ad/Issues/Issue[translate(@date,'-','')>=20080101 and translate(@date,'-','')<=20080301]/Insertion[@ordered]"
XML
---
<Issues>
<Issue date="2008-01-01">
<Insertion/>
</Issue>
<Issue date="2008-05-01">
<Insertion ordered="1499" materialFrom="Materials to follow" issueDate="2008-02-06 1:45:32 PM" changed="0" freq="0" ad="0" manrate="0" pos="0" rcd="0"/>
</Issue>
</Issues>
---
I would appreciate if someone could shed some light. Is there a work around this problem? Has anyone experienced this problem before?
________________________________
This is the full error I get:
name: "TypeError"
message: "Object doesn't support this property or method"
number: -2146827850
description: "Object doesn't support this property or method"
Unknown method.
Media/Vehicle/RateCards/RateCard[@id = '2547' and @name = '2008']/Ads/Ad/Issues/Issue[-->translate(@<--date,'-','')>=20080101 and translate(@date,'-','')<=20080301]/Insertion[@ordered]
Cheers
C
|
|

February 8th, 2008, 09:33 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Can you post the code you are actually running - iexplore is saying that the 'method you are calling' doesn't exist - so what method are you calling?
/- Sam Judson : Wrox Technical Editor -/
|
|

February 8th, 2008, 09:37 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I forget exactly when the defaults changed, but at one time the default language for selectNodes() was not W3C XPath 1.0 but an older Microsoft variant of XPath. You can set the language to XPath by setting the SelectionLanguage property of the IXMLDOMDocument node (using SetProperty()).
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

February 8th, 2008, 09:46 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
If you are using MSXML 3 and the methods selectNodes or selectSingleNode then you first need to call
xmlDocumentInstance.setPoperty('SelectionLanguage' , 'XPath')
in J(ava)script respectively
xmlDocumentInstance.setProperty "SelectionLanguage", "Path"
in VBScript before you can use XPath 1.0 expressions.
|
|

February 8th, 2008, 01:37 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
|
|
I would like to thank you for your reply.
I will make the changes suggested to the selectSingleNode() and see if they fix the problem.
Thanks
CP
|
|

February 8th, 2008, 01:46 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
|
|
Just a quick question.
Is there another way to build this XPATH without using the XPATH translate() function?
If there is I would like to use it since the selectSingleNode() javascript method is part of a javascript library I am using and if I change it something can break elsewhere?
Cheers
CP
|
|

February 8th, 2008, 02:00 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I wouldn't advise you to use the old Microsoft XPath dialect (which IIRC they called "XSL patterns"). It's obsolete and it's almost impossible to find documentation on it. Remember that we're talking about a language that was around for a year from 1998 until it was superseded in 1999. There won't be many people who can help you with it. Also, from my distant memories of it, I suspect it doesn't have the functionality you need.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

February 8th, 2008, 02:28 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
Quote:
quote:Originally posted by pallone
Is there another way to build this XPATH without using the XPATH translate() function?
If there is I would like to use it since the selectSingleNode() javascript method is part of a javascript library I am using and if I change it something can break elsewhere?
|
I think you need the translate function to strip the '-' character from your date values. I don't see any reason not to use it and attempts to avoid it might require other XPath functions.
And setting xmlDocumentInstance.setProperty('SelectionLanguage ', 'XPath') does not hurt with IE 6 and IE 7. The point is as long as you don't set the SelectionLanguage to XPath your arguments to selectSingleNode and selectNodes are not interpreted as XPath expressions and you will always run into problems as you think you are using XPath but it is a predecessor of that language.
|
|

February 8th, 2008, 05:30 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
|
|
Thanks a lot to everyone.
Maybe I will create a function locally that uses the setProperty('SelectionLanguage', 'XPath'). That way, I will not have to change the javascript library.
Cheers
CP
|
|
 |