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

Added XSLT 3.0 support. #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Added XSLT 3.0 support. #74

wants to merge 2 commits into from

Conversation

cmarchand
Copy link

@cirulls
Copy link

cirulls commented Jan 17, 2016

Thanks for submitting the pull request. Would it be possible to share the whole generate-xspec-tests-oxygen.xsl file? I would like to inspect it to see the differences with the current generate-xspec-tests.xsl.

I have oXygen 14.2 and I can see two files generate-xspec-tests.xsl and generate-xspec-tests-oxygen.xsl. The latter imports the former and I wonder this also occurs in the generate-xspec-tests-oxygen.xsl provided with oXygen 17.1. In the pull request there are several lines of code deleted (in particular in the named template x:output-expect) and wonder if this may break things.

@cmarchand
Copy link
Author

Here are the two files.
I've just merged them.

The template x:output-expect-TODO-REMOVE...I-CANT-REMEMBER has been renamed to x:output-expect, and the old x:output-expect has been removed.

Best regards,
Christophe

Sandro Cirulli notifications@github.com wrote:
Thanks for submitting the pull request. Would it be possible to share the whole generate-xspec-tests-oxygen.xsl file? I would like to inspect it to see the differences with the current generate-xspec-tests.xsl.
I have oXygen 14.2 and I can see two files generate-xspec-tests.xsl and generate-xspec-tests-oxygen.xsl. The latter imports the former and I wonder this also occurs in the generate-xspec-tests-oxygen.xsl provided with oXygen 17.1. In the pull request there are several lines of code deleted (in particular in the named template x:output-expect) and wonder if this may break things.

Reply to this email directly or view it on GitHub.

@cirulls
Copy link

cirulls commented Feb 20, 2016

I tested the support for testing XSLT 3.0 with this XSpec test:

<?xml version="1.0" encoding="UTF-8"?>
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="unit-converter.xsl" xslt-version="3.0">

    <x:scenario label="When processing a data element with unit feet">
        <x:context>
            <data>
                <altitude>1200</altitude>
                <unit>feet</unit>
            </data>
        </x:context>

        <x:expect label="convert feet to meters">
            <data>
                <altitude>365.76</altitude>
                <unit>meters</unit>
            </data>
        </x:expect>
    </x:scenario>

</x:description>

It tests the following XSLT which makes use of high-order functions, a new feature of XSLT 3.0 (the example is adapted from www.xfront.com/Pearls-of-XSLT-and-XPath-3-0-Design.pdf).

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:math="http://www.w3.org/2005/xpath-functions/math" exclude-result-prefixes="xs math"
    version="3.0">

    <xsl:variable name="unit-converter"
        select="function(
        $value as xs:decimal,
        $f as function(item()*) as item()*
        )
        as xs:decimal
        {$f($value)}"/>


    <xsl:variable name="feet-to-meters"
        select="function(
        $a as xs:decimal
        )
        as xs:decimal
        {$a * 0.3048}"/>

    <xsl:template match="data[unit='feet']">
        <xsl:copy>
            <altitude>
                <xsl:value-of select="$unit-converter(altitude, $feet-to-meters)"/>
            </altitude>
            <unit>meters</unit>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

I run this test with Oxygen 14.2 (which includes the Oxygen patch) and the test goes through successfully. However, I noticed that with this patch it is compulsory to specify the @xslt-versionwith the value '3.0' when testing an XSLT 3.0. If the attribute is not provided, the Oxygen ant file complains that XPath 3.0 is needed to run the test.

If the patch is changed from:

<stylesheet version="{( @xslt-version, '2.0' )[1]}">

to:

<stylesheet version="{if ( @xslt-version, '3.0' ) then '3' else '2'}">

the XSpec test runs correctly even if @xslt-version is not provided.

I wonder if this implementation may be more suitable as it does not force to specify the @xslt-version in the XSpec test, one only needs to specify the XSLT version in the actual XSL stylesheet. It also seems to me more consistent when writing XSpec tests for XSLT 2.0 as it is not required to specify @xslt-version in the XSpec test.

Unfortunately I'm unable to test this implementation when running XSpec from the command line as XSLT 3.0 requires saxon9ee.jar (I only have saxon9he.jar available).

@fgeorges
Copy link
Member

I am not sure to understand your last comment about the version.

  • if your test suite depends on XSLT 3.0, it is a good idea to tag it as such (with xslt-version="3.0")
  • the code you give is replacing 3.0 by 3 and use 2 for all other cases, is it really what we want? (the original code just use 2.0 as the default, if the version is not provided explicitly)

@fgeorges
Copy link
Member

@cmarchand, why did you remove the new x:output-expect and re-instated the old one?

@cirulls
Copy link

cirulls commented Feb 21, 2016

@fgeorges: Sorry, I've probably not been very clear in my comment. I noticed that if @xslt-version is not provided in the XSpec test, then the test won't compile (at least in Oxygen). As far as I understand, the schema does not force to use @xslt-version but in fact this becomes compulsory if one wants to run an XSpec test for XSLT 3.0. Is this intended? If so, I think it would be good to specify it somewhere as it could lead to confusion (at least it confused me). I'm happy to add this example to the wiki if you think it's appropriate.

As for your second comment, I should have written '2.0' and '3.0' instead of '2' and '3'. I didn't consider 1.0 so you are definitely right.

@fgeorges
Copy link
Member

You mean, "wont' compile", for XSLT 3.0 tests only, right? If so the answer is easy: support for 3.0 is enabled only if xslt-version is set to 3.0. If it is set explicitly, in all cases, the value must be retained. If not, then 2.0 sounds like a sensible default to me, given the 3.0 support at the moment. I suggest then we keep the ( @xslt-version, '2.0' )[1].

@cirulls
Copy link

cirulls commented Feb 21, 2016

Yes, I meant it won't compile for XSLT 3.0 tests only, XSLT 2.0 tests are fine. I agree with your suggestion.

@fgeorges
Copy link
Member

OK, thanks. Now we need to know why @cmarchand removed a big chunk of the implementation :-)

@cmarchand
Copy link
Author

I was looking for having the same result between xspec (out of the box) and xspec in oXygen.But I didn't look at what was inside. And having a template name xxx_old_do_not_use_anymore, when we can register source changes in git, seems very strange. So, I killed a piece of code.
But if oXygen had an older version of xspec, no problem for me.
Regards, Christophe

cirulls referenced this pull request in xspec/xspec Aug 17, 2016
- replace saxon:serialize() with fn:serialize and use XSLT 3.0
- output error message for Saxon8 and Saxon8-SA
- update XSpec unit test (unit test requires support for XSLT 3.0 to run as requested in #74)
- update bats unit test
@cirulls cirulls mentioned this pull request Aug 17, 2016
@cirulls
Copy link

cirulls commented Aug 29, 2016

I re-used this pull request in my fork of XSpec but only used the patch in:

<stylesheet version="{( @xslt-version, '2.0' )[1]}" exclude-result-prefixes="pkg impl">

See my comments in xspec#10

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

Successfully merging this pull request may close these issues.

3 participants