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

Upgrading to XSpec v1.3.0 (or Oxygen v22.0) #778

Open
galtm opened this issue Feb 11, 2020 · 7 comments
Open

Upgrading to XSpec v1.3.0 (or Oxygen v22.0) #778

galtm opened this issue Feb 11, 2020 · 7 comments

Comments

@galtm
Copy link
Collaborator

galtm commented Feb 11, 2020

When upgrading to XSpec 1.3.0, some users might see that some of their pre-existing XSpec tests either have failing assertions or fail to build. The XSpec 1.3.0 Release Notes page contains some relevant information in its Summary section (see 2nd and 6th bullets). This issue provides some examples of how incompatibilities can manifest themselves and options for making the tests pass again.

Oxygen v22.0 has XSpec 1.5.0, whereas Oxygen v21.1 has XSpec 1.2.0. As a result, XSpec users may notice the XSpec 1.3.0 incompatibilities when they adopt Oxygen v22.0.

Sample XSLT

<?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"
  exclude-result-prefixes="xs"
  version="3.0">
  
  <xsl:variable name="outermost_id" select="string(/*/@xml:id)"/>
  <xsl:variable name="outermost_role" select="string(/*/@role)"/>
  <!--
  <xsl:variable name="outermost_role">
    <xsl:try>
      <xsl:value-of select="string(/*/@role)"/>
      <xsl:catch xmlns:err="http://www.w3.org/2005/xqt-errors" errors="err:XPDY0002"/>
    </xsl:try>
  </xsl:variable>
  -->

  <xsl:template name="globalvar" as="xs:string">
    <xsl:value-of select="concat('id=',$outermost_id,', role=',$outermost_role)"/>
  </xsl:template>
  
  <xsl:template name="whitespace">
    <element><xsl:text> </xsl:text></element>
  </xsl:template>
  
  <xsl:template name="param-defaults-to-elem-name" as="xs:string">
    <xsl:param name="key" select="local-name(.)"/>
    <xsl:value-of select="$key"/>
  </xsl:template>

</xsl:stylesheet>

Sample XSpec

<?xml version="1.0" encoding="UTF-8"?>
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="sample.xsl" xslt-version="3.0">
  <x:param name="outermost_id" select="'myIDoverride'"/>
  <!--<x:param name="outermost_role"/>-->
  
  <!--
    Oxygen v21.x: Assertion passes

    Oxygen v22.0: Build failure below
    
     [java] Error evaluating ((<x:label {text{"Global XSLT variable that reference..."}}/>, ...)) in xsl:variable/@select on line 7 column 66 of sample.xsl:
     [java]   XPDY0002: The context item for axis step root/element() is absent
     [java] at template x:d6e4 on line 32 of sample-compiled.xsl:
     [java]      Focus: absent
     [java]      Local variables
     [java]         (All variables are null)
     [java]      invoked by xsl:call-template at file:/.../xspec/sample-compiled.xsl#26
     [java] at template x:main on line 14 of sample-compiled.xsl:
     [java]      invoked by unknown caller (null)
     [java] The context item for axis step root/element() is absent

     Solutions that work in both versions:
     a) In this XSpec document, override $outermost_role; or
     b) In XSLT, ensure global variables provide alternate definitions
        if context item is empty. Consider xsl:try/xsl:catch.
        -->
  <x:scenario label="Global XSLT variables that reference document root">
    <x:context select="/"><element xml:id="myID" role="myrole"/></x:context>
    <x:call template="globalvar"/>
    <x:expect label="id from override and empty role" select="'id=myIDoverride, role='"/>
  </x:scenario>
  
  <!-- =============================== -->
  <!--
    Oxygen v21.x: Assertion passes
    Oxygen v22.0: Build failure from first sub-scenario
    
     [java] Error in xsl:param/@select on line 28 column 51 of sample.xsl:
     [java]   XPDY0002: The context item is absent
     [java] at template gentext on line 27 of sample.xsl:
     [java]      Focus: absent
     [java]      Local variables
     [java]         (All variables are null)
     [java]      invoked by xsl:call-template at file:/.../xspec/sample-compiled.xsl#65
     [java] at template x:d6e9 on line 57 of sample-compiled.xsl:
     [java]      Focus: absent
     [java]      Local variables
     [java]         (All variables are null)
     [java]      invoked by xsl:call-template at file:/.../xspec/sample-compiled.xsl#28
     [java] at template x:main on line 15 of sample-compiled.xsl:
     [java]      invoked by unknown caller (null)
     [java] The context item is absent

     Solutions that work in both versions:
     a) In XSLT, change default value of parameter
     b) In XSLT, stop default value of parameter from being used: either remove it,
        or always specify a value when calling the template

-->
  <x:scenario label="Named template whose default parameter references context item">
    <x:scenario>
      <x:label>
        Template call without specifying 'key' parameter.
        Works in Oxygen v21.x because context is the XSpec document's document node.
        Fails in Oxygen v22.0 because context item is absent.
      </x:label>
      <x:call template="param-defaults-to-elem-name"/>
     <x:expect label="Empty string" select="''"/>
    </x:scenario>
    <x:scenario>
      <x:label>
        Template call specifying 'key' parameter.
        Works in both Oxygen v21.x and v22.0.
      </x:label>
      <x:call template="param-defaults-to-elem-name">
        <x:param name="key"/>
      </x:call>
      <x:expect label="Empty string" select="''"/>
    </x:scenario>
  </x:scenario>

  <!-- =============================== -->
  <x:scenario label="White space in result">
    <x:call template="whitespace"/>
    <x:scenario label="Assertion passes in Oxygen v21.x but not v22.0">
     <x:expect label="Element containing space">
       <element> </element>
     </x:expect>
    </x:scenario>
    <x:scenario label="Assertion passes in Oxygen v22.0 but not v21.x (and x:text is not in older schema)">
      <x:expect label="Element containing space">
        <element><x:text> </x:text></element>
      </x:expect>
    </x:scenario>
    <x:scenario label="Assertions pass in both Oxygen v21.x and v22.0">
      <x:expect xml:space="preserve" label="Element containing space"><element> </element></x:expect>
    </x:scenario>
    <x:scenario label="Assertions pass in both Oxygen v21.x and v22.0">
      <x:expect label="Element"><element>...</element></x:expect>
      <x:expect label="containing space" test="/element/string()" select="' '"/>
    </x:scenario>
  </x:scenario>
</x:description>
@galtm
Copy link
Collaborator Author

galtm commented Feb 11, 2020

@AlexJitianu, I thought you might want to be aware of this (if you're not already), in case Syncro Soft receives questions or tech support cases related to the XSpec upgrade.

@AirQuick AirQuick pinned this issue Feb 11, 2020
@AlexJitianu
Copy link

Thanks for the heads-up! Up until now, the only report we had was related to the addon that contributes the XSpec Helper View. I will release a new version that is compatible with Oxygen version 22.

@apaluya
Copy link

apaluya commented Mar 5, 2020

@AlexJitianu thanks for your response to me on the OxygenXML support channel, I sent a note about this issue yesterday.

I've got XSL that handles DITA to markdown, backed by XSpec tests. Until the latest upgrades (Saxon 9.9, XSpec 1.3, OxygenXML 22), these tests worked as expected. Now, they fail because of a Saxon SXD0004 error -- in short, the result doc is not XML. That is, running XSpec tests, targeting XSL transforms to text, with the latest of everything produces an error that emanates from Saxon.

I created bare-bones test documents (attached). When I ran the included sample.xspec file in OxygenXML 22, I got the above-mentioned error -- that is, the test doesn't compile correctly.

I then installed XSpec locally, installed Saxon 9.8.0.14 locally, and from the CLI ran xspec against my sample file. The tests compile correctly, which is good, but fail for some whitespace issue that I haven't been able to solve -- but that is a different matter. The important point is that the test compiles, so this tells me that using Saxon 9.8.0.14 works w/ XSpec for text output (markdown in this case), whereas the 9.9 version doesn't. This may or may not be useful information for you.

I was going to file a new issue, but I found this one, and it seems relevant, hence my comment here.

Meanwhile, while I'm here I'd like to say that I have great appreciation for both SyncroSoft and XSpec, I use these tools regularly and am impressed with the high level of work that you're all doing.

xspec-test-samples.zip

@AirQuick
Copy link
Member

AirQuick commented Mar 5, 2020

Hi, @apaluya
"running XSpec tests, targeting XSL transforms to text" is a Saxon 9.9 bug which will be fixed in the next maintenance version (9.9.1.7...? probably). (#638)

@AirQuick
Copy link
Member

AirQuick commented Mar 5, 2020

The reason why the sample test fails on Saxon 9.8 is that an extra LF is expected.

 paragraph.&#xA;&#xA;</x:expect>

If the last LF in x:expect is deleted, the test passes.

 paragraph.&#xA;</x:expect>

But the XSpec result HTML reports this simple difference as if it were a complicated difference. That needs to be fixed in XSpec.

@AirQuick
Copy link
Member

But the XSpec result HTML reports this simple difference as if it were a complicated difference. That needs to be fixed in XSpec.

Fixed in #824

@AirQuick
Copy link
Member

#873 is one of the instances of the global context item issue.

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