Skip to content
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

Does XSpec specify an implicit default context? #73

Open
adamretter opened this issue Jan 14, 2016 · 4 comments
Open

Does XSpec specify an implicit default context? #73

adamretter opened this issue Jan 14, 2016 · 4 comments

Comments

@adamretter
Copy link
Member

If we look at the scripts provided for executing XSpec:

  1. Bash - https://github.com/expath/xspec/blob/master/bin/xspec.sh#L259
  2. Windows Batch - https://github.com/expath/xspec/blob/master/bin/xspec.bat#L73
  3. Ant - https://github.com/expath/xspec/blob/master/build.xml#L97

We see that each of them invoke Saxon to execute the XSpec. However, they also tell Saxon to set the input document to that of the original foo.xspec file, by using the -s: argument, even though they also set an initial named template for execution using the -it: argument.

This doesn't seem to make any sense to me. XSpec provides x:context for setting the context of a Scenario. Also I can't imagine why you would ever want a default implicit context which was the content of your XSpec.

Is this a mistake/bug or is this by intention? If this is by intention, then can someone please explain what the use-case is, as I can't see it yet!

@cirulls
Copy link

cirulls commented Jan 16, 2016

I'm not the best person to answer this as I'm just getting to grips with the codebase but I give my two pennies worth contribution - with the risk of stating the obvious or the erroneous.

Regarding the -s and -it flag, I can read the following in the Saxon documentation:

-s:filename: Identifies the source file or directory. Mandatory unless the -it option is used. The source file is parsed to create a tree, and the document node of this tree acts as the initial context item for the transformation. [...]

-it:template: Selects the initial named template to be executed. If this is namespaced, it can be written as {uri}localname. When this option is used, you do not need to supply a source file, but if you do, you must supply it using the -s option.

The shell script xspec.sh (as well as the batch and ant scripts) are run with both flags:

xslt -o:"$RESULT" -s:"$XSPEC" -xsl:"$COMPILED" \
     -it:{http://www.jenitennison.com/xslt/xspec}main \

The -s flag is set to the foo.xspec file passed by the user when running xspec and the -it flag is set to the named template main in generate-xspec-test.xsl.

I ran the shell script without the -s flag using the tutorial xspec example :

xslt -o:"$RESULT" -xsl:"$COMPILED" \
     -it:{http://www.jenitennison.com/xslt/xspec}main \

and it produced the same output at the terminal as well as the same XML and HTML reports. However, I have not yet tested it with the batch and ant scripts nor with an XQuery example.

This makes me think that the -s flag is not necessary (let alone inconsistent) and I agree with you that it doesn't make sense to set the XSpec document as the initial context of the transformation.

Can anyone see a use case for this? Running it without -s flag is going to break other things?

@michaelhkay
Copy link
Member

I don't know about XSpec, but it's perfectly OK to have both an initial named template and a source document for a transformation. It's useful for example if you want a stylesheet with multiple entry points to do either a summary report or a full report on the same input document. The source document is available (as the value of ".") both within the initial named template, and within global variables.

Michael Kay
Saxonica

On 16 Jan 2016, at 17:53, Sandro Cirulli notifications@github.com wrote:

I'm not the best person to answer this as I'm just getting to grips with the codebase but I give my two pennies worth contribution - with the risk of stating the obvious or the erroneous.

Regarding the -s and -it flag, I can read the following in the Saxon documentation http://www.saxonica.com/documentation9.5/using-xsl/commandline.html:

-s:filename: Identifies the source file or directory. Mandatory unless the -it option is used. The source file is parsed to create a tree, and the document node of this tree acts as the initial context item for the transformation. [...]

-it:template: Selects the initial named template to be executed. If this is namespaced, it can be written as {uri}localname. When this option is used, you do not need to supply a source file, but if you do, you must supply it using the -s option.

The shell script xspec.sh https://github.com/expath/xspec/blob/master/bin/xspec.sh#L259 (as well as the batch and ant scripts) are run with both flags:

xslt -o:"$RESULT" -s:"$XSPEC" -xsl:"$COMPILED"
-it:{http://www.jenitennison.com/xslt/xspec}main
The -s flag is set to the foo.xspec file passed by the user when running xspec and the -it flag is set to the named template main in generate-xspec-test.xsl https://github.com/expath/xspec/blob/master/src/compiler/generate-xspec-tests.xsl#L64.

I ran the shell script without the -s flag using the tutorial xspec example https://github.com/expath/xspec/blob/master/tutorial/escape-for-regex.xspec :

xslt -o:"$RESULT" -xsl:"$COMPILED"
-it:{http://www.jenitennison.com/xslt/xspec}main
and it produced the same output at the terminal as well as the same XML and HTML reports. However, I have not yet tested it with the batch and ant scripts nor with an XQuery example.

This makes me think that the -s flag is not necessary (let alone inconsistent) and I agree with you that it doesn't make sense to set the XSpec document as the initial context of the transformation.

Can anyone see a use case for this? Running it without -s flag is going to break other things?


Reply to this email directly or view it on GitHub #73 (comment).

@tgraham-antenna
Copy link
Member

On 14/01/2016 18:48, Adam Retter wrote:
...

We see that each of them invoke Saxon to execute the XSpec. However,
they also tell Saxon to set the input document to that of the
original |foo.xspec| file, by using the |-s:| argument, even though
they also set an initial named template for execution using the
|-it:| argument.

I thought there was a time when you still needed to provide a source
document when you used |-it:|, but I trawled the Saxon documentation
back to Saxon 8.9, and it wasn't required then, so I think I'm either
wrong or I'm thinking about the Ant task.

This doesn't seem to make any sense to me. XSpec provides |x:context|
for setting the context of a Scenario. Also I can't imagine why you
would ever want a default implicit context which was the content of
your XSpec.

Sometimes the XSpec is all that you have (if you need to supply a source
document, that is).

Is this a mistake/bug or is this by intention? If this is by
intention, then can someone please explain what the use-case is, as I
can't see it yet!

On mature recollection, it might have been needed for Ant at one time
but not necessarily for the others.

I looked at how Jeni's previous test framework did it, but it used an
older Saxon version so didn't have |-it:| anyway.

Regards,

Tony.

@adamretter
Copy link
Member Author

@tgraham-antenna So in your conclusion, is it the case that we no longer need to set an initial default context, as there appears to be no current reason to do so?

Otherwise, can we somewhere in the XSpec spec have it stated that there is an initial default context which should be the XSpec itself?

It would be nice to get this nailed down :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants