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

xspec produces a different transformation than expected #59

Open
GoogleCodeExporter opened this issue Jun 8, 2015 · 8 comments
Open

Comments

@GoogleCodeExporter
Copy link

When running a scenario that asks xspec to transform a document first and then 
test the output, xspec's transformation is generating the wrong result (or I am 
using it wrong).

This is a sample scenario:

    <x:scenario label="Scenarios for testing Choice handling" focus="Working out Choice handling">
        <x:context href="NEHTA-00009-Adverse_Reaction-Structure (sample data).xml" select="/"></x:context>
        <x:expect label="Abstract class in the uml:Model with an isAbstract attribute">
            <packagedElement></packagedElement>
        </x:expect>
    </x:scenario>


The source transformation has this message in it to test that a variable was 
created right:

<xsl:message select="concat('The package name is: ', 
$packagename)"></xsl:message>

And the variable is defined as:

<xsl:variable name="packagename" 
select="concat(/ci-spec:DataGroup/ci-spec:Specification/@name, ' v', 
/ci-spec:DataGroup/ci-spec:Specification/@version, ' draft ', 
/ci-spec:DataGroup/ci-spec:Specification/@draft-nr )"></xsl:variable>

The transformation, when run with Saxon-HE within oXygen, works fine. It also 
works fine when I used the same version of Saxon manually just to confirm.

However, using xspec within oxygen 14.2, the output that I get is:

The package name is:  v draft

Which indicates a problem (and has many more). I created another transformation 
in Oxygen that used Saxon-HE instead of Saxon-EE - same error. I then ran xspec 
0.4-rc1 manually using the same saxon-he version, and it had the same problem. 
Same deal with 0.3.

So either I'm really not using xspec right, or it is having issues applying a 
transformation properly. I wondered if the problem is with namespaces, but that 
didn't seem to affect anything.

This is the template that gets generated for this scenario:

   <xsl:template name="x:d4e39">
      <xsl:message>Scenarios for testing Choice handling</xsl:message>
      <x:scenario>
         <x:label>Scenarios for testing Choice handling</x:label>
         <x:context href="file:/C:/Users/VadimPeretokin/Desktop/dcm2ea/NEHTA-00009-Adverse_Reaction-Structure%20(sample%20data).xml"
                    select="/"/>
         <xsl:variable name="x:result" as="item()*">
            <xsl:variable name="impl:context-doc"
                          as="document-node()"
                          select="doc('file:/C:/Users/VadimPeretokin/Desktop/dcm2ea/NEHTA-00009-Adverse_Reaction-Structure%20(sample%20data).xml')"/>
            <xsl:variable name="impl:context" select="$impl:context-doc/(/)"/>
            <xsl:apply-templates select="$impl:context"/>
         </xsl:variable>
         <xsl:call-template name="test:report-value">
            <xsl:with-param name="value" select="$x:result"/>
            <xsl:with-param name="wrapper-name" select="'x:result'"/>
            <xsl:with-param name="wrapper-ns" select="'http://www.jenitennison.com/xslt/xspec'"/>
         </xsl:call-template>
         <xsl:call-template name="x:d4e41">
            <xsl:with-param name="x:result" select="$x:result"/>
         </xsl:call-template>
      </x:scenario>
   </xsl:template>
   <xsl:template name="x:d4e41">
      <xsl:param name="x:result" required="yes"/>
      <xsl:message>Abstract class in the uml:Model with an isAbstract attribute</xsl:message>
      <xsl:variable name="impl:with-context"
                    select="                          exists($x:result) and empty($x:result[2])"/>
      <xsl:variable name="impl:context" as="item()?">
         <xsl:choose>
            <xsl:when test="$impl:with-context">
               <xsl:sequence select="$x:result"/>
            </xsl:when>
            <xsl:otherwise/>
         </xsl:choose>
      </xsl:variable>
      <xsl:variable name="impl:expected-doc" as="document-node()">
         <xsl:document>
            <packagedElement/>
         </xsl:document>
      </xsl:variable>
      <xsl:variable name="impl:expected" select="$impl:expected-doc/node()"/>
      <xsl:variable name="impl:successful"
                    as="xs:boolean"
                    select="                    test:deep-equal(                      $impl:expected,                      if ( $impl:with-context ) then $impl:context else $x:result,                      2)"/>
      <xsl:if test="not($impl:successful)">
         <xsl:message>      FAILED</xsl:message>
      </xsl:if>
      <x:test successful="{ $impl:successful }">
         <x:label>Abstract class in the uml:Model with an isAbstract attribute</x:label>
         <xsl:call-template name="test:report-value">
            <xsl:with-param name="value" select="$x:result"/>
            <xsl:with-param name="wrapper-name" select="'x:result'"/>
            <xsl:with-param name="wrapper-ns" select="'http://www.jenitennison.com/xslt/xspec'"/>
         </xsl:call-template>
         <xsl:call-template name="test:report-value">
            <xsl:with-param name="value" select="$impl:expected"/>
            <xsl:with-param name="wrapper-name" select="'x:expect'"/>
            <xsl:with-param name="wrapper-ns" select="'http://www.jenitennison.com/xslt/xspec'"/>
         </xsl:call-template>
      </x:test>
   </xsl:template>

Original issue reported on code.google.com by vpereto...@gmail.com on 13 Aug 2013 at 1:43

@GoogleCodeExporter
Copy link
Author

One thing I realized is that I was expecting all of my templates (starting from 
the main driving one) to run it - which seemed like they all did, but certain 
ones have failed to work.

I've since setup a case where I feed it a document and a selected location, and 
then feed that to a select template - and that processed it right... but this 
case is still eluding me.

Original comment by vpereto...@gmail.com on 13 Aug 2013 at 10:36

@GoogleCodeExporter
Copy link
Author

Issue 60 has been merged into this issue.

Original comment by fgeorges on 14 Aug 2013 at 3:25

@GoogleCodeExporter
Copy link
Author

Any chance that you could send a complete example? (like the test suite, the 
stylesheet and the input file)  Ideally minimized to a short one...

Original comment by fgeorges on 14 Aug 2013 at 3:30

@GoogleCodeExporter
Copy link
Author

Yes certainly - here is a minimized test case.

This is what I get with it - it also seems to bug out internally, but from the 
xsl:message, you can tell that the name isn't being made right anyway:

PS C:\Users\VadimPeretokin\Desktop\dcm2ea> 
C:\Tools\xspec-0.4.0rc1\bin\xspec.bat .\DCM2EA.xspec
Creating Test Stylesheet...
"C:\Users\VadimPeretokin\Desktop\dcm2ea\xspec\DCM2EA.xsl"
.\DCM2EA.xspec

Running Tests...
Testing with SAXON HE 9.4.0.9
Cut-down test to see the $packagename
The package name is:  v draft
Package name should be properly formed
Error on line 66 of DCM2EA.xsl:
  XPDY0050: The root of the tree containing the context item is not a document node
Transformation failed: Run-time errors were reported

Formatting Report...
Error on line 1 column 1 of DCM2EA-result.xml:
  SXXP0003: Error reported by XML parser: Premature end of file.
Transformation failed: Run-time errors were reported
Done.
PS C:\Users\VadimPeretokin\Desktop\dcm2ea>

If you run the xsl on the source sample file, you'll get this result:

<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmlns:uml="http://www.omg.org/spec/UML/20101101"
         xmlns:xmi="http://www.omg.org/spec/XMI/20101101"
         xmi:version="2.4">
   <xmi:Documentation exporter="Enterprise Architect" exporterVersion="6.5"/>
   <uml:Model xmi:type="uml:Model" name="DCM Model" visibility="public">
      <packagedElement xmi:type="uml:Package"
                       xmi:id="d1e3"
                       name="Adverse Reaction v5.1 draft 72"
                       visibility="public"/>
   </uml:Model>
</xmi:XMI>

Which is obviously different than from what xspec produces when it runs the 
transformation.

Saxon-HE is used in all cases here as the transformer.

Original comment by vpereto...@gmail.com on 14 Aug 2013 at 11:33

Attachments:

@GoogleCodeExporter
Copy link
Author

Is any other information needed for this? I'm hoping I'm just doing something 
wrong, as this issue really affects the usability of xspec.

Original comment by vpereto...@gmail.com on 19 Aug 2013 at 3:48

@GoogleCodeExporter
Copy link
Author

THe error doesn't seem to be relevant and seems to happen due to some xslt 
limitation - replacing /xmi:XMI with descendant-or-self:: fixes the error, yet 
the issue of the invalid variable text being generated is still there.

Original comment by vpereto...@gmail.com on 20 Aug 2013 at 11:43

@GoogleCodeExporter
Copy link
Author

Doing some more digging on this and solved the problem. The base-uri() of 
variables declared the top level element, not in a template, is wrong: it'll be 
set to the xspec file. That's why global variables can't select anything 
right... and thus can't be used within xspec really.

Is there any possible solution to this?

Original comment by vpereto...@gmail.com on 21 Aug 2013 at 3:07

@GoogleCodeExporter
Copy link
Author

http://stackoverflow.com/questions/18349331/how-to-to-get-the-desired-base-uri-w
hen-xsl-is-run-from-another-file/18522563 has more analysis.

Original comment by vpereto...@gmail.com on 28 Sep 2013 at 8:17

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

No branches or pull requests

1 participant