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 September 27th, 2006, 08:48 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default Xpath error in Document()

Hi all,

In reference to this post:

http://p2p.wrox.com/topic.asp?TOPIC_ID=50270 which was answered by Michael Kay

This xpath works fine when parsing outside of ASP.net:




Code:
    <xsl:template match="JBU:share">
   <xsl:for-each select="document(@loc)/id(current()/@item)">
    <xsl:apply-templates/>
    </xsl:for-each>


I am recieving the following error when trying to parse through ASP 2.0

"'document(@loc)/id(current()/@item)' is an invalid XPath expression"


Do I need to go to XSLT 1.0? And if so how?

Thanks for the help.

 
Old September 28th, 2006, 02:29 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The expression document(@loc)/id(current()/@item is valid in XSLT 2.0 but not in XSLT 1.0. In a 1.0 processor you can write:

<xsl:template match="JBU:share">
  <xsl:variable name="x" select="@item"
  <xsl:for-each select="document(@loc)">
    <xsl:apply-templates select="id(@x)/node()"/>
  </xsl:for-each>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 28th, 2006, 03:53 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Thanks Michael,

I am recieving the following error:

The variable or parameter 'x' cannot have both a 'select' attribute and non-empty content

Thanks,

Bones


 
Old September 28th, 2006, 04:53 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I think you need to close the variable:
Code:
<xsl:variable name="x" select="@item"/>
<xsl:for-each select="document(@loc)">
--

Joe (Microsoft MVP - XML)
 
Old September 28th, 2006, 05:11 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>The variable or parameter 'x' cannot have both a 'select' attribute and non-empty content


Could you please tell me *why* you were unable to understand that error message and correct the code?

I genuinely want to know the answer. I try very hard to construct error messages that are clear to users, even users unfamiliar with the detailed rules of the language. If I can make this message clearer, I would love to do so.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 28th, 2006, 05:56 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Michael,

Sometimes the most obvious escapes me, coupled with the fact that I am sometimes "thick headed".

My first guess would be that the @item is empty or that the attribute would need change to a "required" rather than "optional" in my schema.

I appreciate the help. If you can get the answer out of me, I will learn more.

Thanks,

Bones
 
Old September 28th, 2006, 07:39 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Michael,

As I trouble shoot this error I have a question. With a <xsl:variable> element, once you have set a variable's value, you cannot change or modify it. But the template is asking it to change, provoking the error. If @item is a variable (because I need it to select different IDs from and XML document) then how can I use it?

Thanks,

 
Old September 29th, 2006, 02:10 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I've no idea what you mean by saying "the template is asking it [the variable] to change".

Although a variable, once instantiated, cannot change its value, it can have different values each time it is instantiated. Usually this is achieved by defining parameters to a template, but in fact it's true of any local variable that its value varies from one invocation of the containing template to another.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 29th, 2006, 06:25 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Michael,

Thank your for the insight. I continue to read and try to learn. This is what I have so far. I am at work and can not try it, but am I close?

Code:
<xsl:template match="JBU:share">
  <xsl:variable name="x" select="@item"/>
  <xsl:for-each select="document(@loc)">
    <xsl:apply-templates select="id($x)/node()"/>
  </xsl:for-each>


In

Code:
 <xsl:apply-templates select="id($x)/node()"/>
I changes the '@' to '$' to pick up the variable. Is this correct?

Thanks for the help.

Bones


 
Old September 29th, 2006, 06:44 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Yes, this looks OK.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





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
XPath Error tclotworthy XSLT 4 March 1st, 2007 07:20 PM
XPath API and DOM Document object nnravi XML 10 May 2nd, 2006 12:24 PM
XSLT -XPATH Error xslspy XSLT 1 October 27th, 2005 03:24 AM
XPath Evaluate Document safin XML 2 September 19th, 2005 07:29 AM





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