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 November 28th, 2007, 10:34 AM
Authorized User
 
Join Date: Nov 2007
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
 
Old November 28th, 2007, 10:38 AM
Friend of Wrox
 
Join Date: Nov 2007
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

 
Old November 28th, 2007, 10:43 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
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 -/
 
Old November 29th, 2007, 06:28 AM
Authorized User
 
Join Date: Nov 2007
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
 
Old November 29th, 2007, 06:59 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
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
 
Old November 29th, 2007, 07:51 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)
 
Old November 29th, 2007, 08:37 AM
Authorized User
 
Join Date: Nov 2007
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')] '
 
Old November 29th, 2007, 08:48 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
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
 
Old November 29th, 2007, 09:01 AM
Authorized User
 
Join Date: Nov 2007
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.
 
Old November 29th, 2007, 09:37 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
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 -/





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





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