Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
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 November 28th, 2007, 10:34 AM
Authorized User
 
Join Date: Nov 2007
Location: , , Ireland.
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Hughesie78
Default XPath Invalid token

I Have an issue with XPATH and im looking for some help
Here is my code behind on my aspx page
XmlNodeList codelist = bankdoc.SelectNodes("//bank[text() = '" + GetXPathString(strBank) + "'] and ..branch[text()= '" + GetXPathString(strBranch) + "'] ");

GetXPathString is a fxn to concat the 2 string, here it is

           public static string GetXPathString(string input)
           {
               string [] fragments = input.Split(new char[] {'\''});
               string result = "";
               result += "concat(''";
               for (int i = 0; i < fragments.Length; i++)
               {
                   result += ", '" + fragments[i] + "'";
                   if (i < fragments.Length - 1)
                   {
                       result += ", \"'\"";
                   }
               }
               result += ")";
              return result;


           }

However when I run I get the error;
'//bank[text() = 'concat('', 'XXX rrrreee')'] and ..branch[text()= 'concat('', 'xxx wwwwol')'] ' has an invalid token.
Exception Details: System.Xml.XPath.XPathException: '//bank[text() = 'concat('', 'XXX rrrreee')'] and ..branch[text()= 'concat('', 'XXX rrrreee')'] ' has an invalid token.

any ideas?
__________________
Thank You
Reply With Quote
  #2 (permalink)  
Old November 28th, 2007, 10:38 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I have not checked the complete code but you can't have ..branch, that needs to be ../branch

Reply With Quote
  #3 (permalink)  
Old November 28th, 2007, 10:43 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

concat is a function, so shouldn't be inside single quotes

Wrong: text()='concat('a','b')'

Correct: text()=concat('a', 'b')

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #4 (permalink)  
Old November 29th, 2007, 06:28 AM
Authorized User
 
Join Date: Nov 2007
Location: , , Ireland.
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Hughesie78
Default

Hey , ive removed the single quotes from around the concat, thanks, I am still receining this error thou:

'//bank[text() = concat('', 'Clears through Bank name’)] and ..branch[text()= concat('', 'london uk')] ' has an invalid token.

Here is the code now:
XmlNodeList codelist = bankdoc.SelectNodes("//bank[text() = " + GetXPathString(strBank) + "] & ..branch[text()= " + GetXPathString(strBranch) + "] ");
Also have tried
XmlNodeList codelist = bankdoc.SelectNodes("//bank[text() = " + GetXPathString(strBank) + "] and ..branch[text()= " + GetXPathString(strBranch) + "] ");


When Split this code i.ie
XmlNodeList codelist = bankdoc.SelectNodes("//bank[text()= " + GetXPathString(strBank) + "] ");
OR
XmlNodeList codelist = bankdoc.SelectNodes("//branch[text()= " + GetXPathString(strBranch) + "] ");
It works fine, it ojnly gives me the erroer when I want to query 2 nodes, so i must doing something wrong in the ‘AND’ part , any ideas, im lost.
Here is my XML:

basically I am trying to select the <nsc> element, from the values of 2 drop down menus, the first selects <bank> (it’s a distinct list of banks) and the seconds selects <branch> and list of all branchs for the bank selected , I want to print the <nsc> value to a text box.

  <Bank>
    <nsc>000000</nsc>
    <bank>Clears through bank name</bank>
    <branch>london uk</branch>
    <address1>The Square</address1>
    <address2> </address2>
    <address3> </address3>
    <keywords> </keywords>
    <telephone></telephone>
    <fax></fax>
    <atm>Yes</atm>
  </Bank>

Hope this makes sense
Reply With Quote
  #5 (permalink)  
Old November 29th, 2007, 06:59 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Since the bug was in your GetXPathString() method, and you haven't shown the new version of the method, one must assume that you haven't corrected it successfully.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #6 (permalink)  
Old November 29th, 2007, 07:51 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

It would be easier to debug if we could see the actual XPath generated.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #7 (permalink)  
Old November 29th, 2007, 08:37 AM
Authorized User
 
Join Date: Nov 2007
Location: , , Ireland.
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Hughesie78
Default

hi
sorry, here is my method
          public static string GetXPathString(string input)
           {
               string [] fragments = input.Split(new char[] {'\''});
               string result = "";
               result += "concat(''";
               for (int i = 0; i < fragments.Length; i++)
               {
                   result += ", '" + fragments[i] + "'";
                   if (i < fragments.Length - 1)
                   {
                       result += ", \"'\"";
                   }
               }
               result += ")";
              return result;

           }


here is the XPATH :
'//bank[text() = concat('', 'Clears through Bank name')] and ..branch[text()= concat('', 'Bank aa')] '
Reply With Quote
  #8 (permalink)  
Old November 29th, 2007, 08:48 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I think someone already pointed out that

..branch

is not valid, you presumably intended ../branch

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #9 (permalink)  
Old November 29th, 2007, 09:01 AM
Authorized User
 
Join Date: Nov 2007
Location: , , Ireland.
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Hughesie78
Default

i tried that, my code/xpathIs now:
XmlNodeList codelist = bankdoc.SelectNodes("//bank[text() = " + GetXPathString(strBank) + "] and ../branch[text()= " + GetXPathString(strBranch) + "] ");
when i run i get this eror:
Expression must evaluate to a node-set.
Reply With Quote
  #10 (permalink)  
Old November 29th, 2007, 09:37 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

Basically you're xpath looks like this:

//bank[text()='A'] and ../branch[text()='B']

The problem is that the 'and' is not inside a predicate (i.e. square brackets []).

What are you trying to return? bank elements, or branch elements?

Can we see a segment of your input XML? Is branch the parent of bank, or vice versa?



/- Sam Judson : Wrox Technical Editor -/
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
xpath contains error 'has an invalid token' XMLUser XSLT 7 February 5th, 2008 02:31 AM
Invalid Token sani723 XSLT 2 December 25th, 2007 01:42 AM
error LNK2020 unresolved token rachappa Visual C++ 1 January 12th, 2006 08:05 AM
WSE 2.0 Sending Username Token jpitzer .NET Web Services 2 April 28th, 2005 02:17 PM
Unrecognized token was found Dennis Huisman BOOK: Professional Crystal Reports for VS.NET 0 September 6th, 2004 07:08 AM



All times are GMT -4. The time now is 11:23 AM.


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