Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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 Search this Thread Display Modes
  #1 (permalink)  
Old February 8th, 2008, 09:25 AM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #2 (permalink)  
Old February 8th, 2008, 09:33 AM
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,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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 -/
Reply With Quote
  #3 (permalink)  
Old February 8th, 2008, 09:37 AM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

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
Reply With Quote
  #4 (permalink)  
Old February 8th, 2008, 09:46 AM
Friend of Wrox
Points: 6,673, Level: 34
Points: 6,673, Level: 34 Points: 6,673, Level: 34 Points: 6,673, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,242
Thanks: 0
Thanked 244 Times in 243 Posts
Default

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.

Reply With Quote
  #5 (permalink)  
Old February 8th, 2008, 01:37 PM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #6 (permalink)  
Old February 8th, 2008, 01:46 PM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #7 (permalink)  
Old February 8th, 2008, 02:00 PM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

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
Reply With Quote
  #8 (permalink)  
Old February 8th, 2008, 02:28 PM
Friend of Wrox
Points: 6,673, Level: 34
Points: 6,673, Level: 34 Points: 6,673, Level: 34 Points: 6,673, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,242
Thanks: 0
Thanked 244 Times in 243 Posts
Default

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.

Reply With Quote
  #9 (permalink)  
Old February 8th, 2008, 05:30 PM
Friend of Wrox
Points: 1,243, Level: 13
Points: 1,243, Level: 13 Points: 1,243, Level: 13 Points: 1,243, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , United Kingdom.
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Problem in Using xpath() function in Biztalk mamatharocks Biztalk 2 September 9th, 2013 02:57 AM
sum and translate in XPath nwright BOOK: XSLT Programmer's Reference, 2nd Edition 2 December 5th, 2008 08:20 AM
Problem with xpath function Phanikumar Biztalk 1 May 22nd, 2008 02:32 AM
Sum function and XPath problems tslag XSLT 2 June 26th, 2006 10:23 AM
Xpath: sum function gracehanh XSLT 13 September 27th, 2005 09:30 AM



All times are GMT -4. The time now is 06:40 PM.


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