-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
escaping XPath expressions in attributes #29
Comments
Thanks for raising this question, I'll have a look at what is happening under the hood and let you know. Please allow me 7-10 days to get back to you as it is Christmas time. |
@cmarchand : can you give me the full XSpec test and XSLT you're testing so that I can reproduce the issue and see at which point it is causing problems? |
Attached. The XSL is not important, all the problem is in the Xspec, when compiling the generated XSL. |
I had a look at your zip file. First of all, I think there is an extra closing curly brace in the XSpec test as I can see this: <simple attr="Q{http://www.jenitennison.com/xslt/xspec}scenario}"/> I think you wanted to write this (note that there is no closing curly brace after scenario): <simple attr="{http://www.jenitennison.com/xslt/xspec}scenario"/> Also, I'm not sure what the When running the XSpec test with this version of the
I believe this occurs because the curly braces identify attribute value templates. Curly braces inside attribute values allow to evaluate the result of an expression. Therefore what is inside the curly braces gets evaluated into an XPath expression, hence the error. If you don't want to evaluate it, you need to use the double curly braces as you correctly suggest. I believe this is the expected behaviour in XPath/XSLT and it is not linked to the XSpec implementation. There are other ways to get the same result and this may help you in case you need to evaluate the value of a variable inside an attribute:
I hope this addresses you question or helps to clarify it. |
|
You are right, the last closing curly brace shouldn't be there. If you escape the curly braces as XSLT expect - doubling them - , then there is no more compilation error, and the value is what I expect :
|
Thanks for letting me know about Is the solution with double curly braces fine with you? Can I close this issue? |
All the solutions provided in this thread are fine. The question is: is it a xspec writer's responsability to escape de curly braces, or should the xspec compiler do it ? Whatever the answer, it have to be written in the documentation. For me, it's fine to say the xspec writer knows enough XSL stuff to be able to escape the curly braces in x:context and x:expect |
I added it to the documentation at the end of the section Matching Scenarios. Are you happy with this change in the documentation? |
That's perfect !Thanks a lot !
One of my colleagues point me something :
on <x:expect, there are two undocumented attributes : context & assert. context is an XPath expression that points the part of the result the expect applies on assert is a boolean expression that applies on the `context` result, and works as the schematron assert.
Here is a sample on a function that returns an attribute :<x:expect label="Le test suivant doit renvoyer true()" context="." assert="(. instance of attribute()) and (name(.) = 'style') and (string(.) = 'rjTdmGlobale')"/>
Have you ever used this ?
Best,Christophe
|
context and assert seem to have been introduced rather quietly in haste. |
Thanks @cmarchand and @AirQuick for your input. @cmarchand : I edited your last comment and removed my reply at the end so that it is easier to read. I also removed the notation @ followed by attribute name as this is automatically converted into a GitHub handle which notifies GitHub users. Please do not use this common XML notation as GitHub users have already complained in the past. I suggest to close this issue as I updated the documentation. If you want to discuss further the removal of attributes |
While I was looking into other issues, I found this issue to be just one of similar bugs. |
Fix submitted: #454 @cmarchand |
Updated Wiki to reflect the fact. |
Wiki change describes precisely the problem, and solution is clear. Perfect. |
@cmarchand |
Ok, I didn't look at the PR. |
Sorry! So you need to escape curly braces. |
Such a scenario generates non-compilable XSL code :
Because of the curly brackets in the attribute value, when copied inside a <xsl:* /> element, XSL compiler tries to execute the XPath expression.
If in the context, I double the curly braces, then it works correctly. But is it xspec writer responsability to escape the curly braces, or it is xspec compiler responsability ?
The text was updated successfully, but these errors were encountered: