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

September 27th, 2006, 08:48 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
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.
|
|

September 28th, 2006, 02:29 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

September 28th, 2006, 03:53 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
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
|
|

September 28th, 2006, 04:53 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

September 28th, 2006, 05:11 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
>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
|
|

September 28th, 2006, 05:56 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
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
|
|

September 28th, 2006, 07:39 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
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,
|
|

September 29th, 2006, 02:10 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

September 29th, 2006, 06:25 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
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
|
|

September 29th, 2006, 06:44 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Yes, this looks OK.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
 |