0

I use xspec for testing of stylesheets. Most of the time it works fine, but once in a while tests fail without a valid reason: the expected and the actual result are the same. Seemingly: everything is green in the comparison screen. In that case, I mostly get it working again after trying all kinds of things, but without knowing what change 'did it'.

It would be most helpful if xspec would report the reason of the failure, but if you can help me (instead of the xspec output) to shine some light on this, I'd be very happy.

This is a reduced test case: xsl:

<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:uc="http://www.infinity-loop.de/namespace/upcast/4.0/"
  xmlns:xlink="http://www.w3.org/1999/xlink" 
  xmlns:html="http://www.w3.org/HTML/1998/html4"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="uc xlink html xs xsl">

  <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>

  <xsl:template match="bezwaar">
    <xsl:variable name="content">
      <xsl:element name="{name()}">
        <xsl:apply-templates select="@*|node()"/>
      </xsl:element>
    </xsl:variable>
    <xsl:copy-of select="$content"/>
  </xsl:template>

  <xsl:template match="@*" >
    <xsl:attribute name="{name()}" namespace="{namespace-uri()}">
      <xsl:value-of select="." />
    </xsl:attribute>
  </xsl:template>

  <xsl:template match="*">
    <xsl:element name="{name()}" namespace="{namespace-uri()}">
      <xsl:apply-templates select="@*|node()" />
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

xspec:

<?xml version="1.0" encoding="UTF-8"?>
<x:description
    xmlns:x = "http://www.jenitennison.com/xslt/xspec"
    stylesheet="file:/home/rdgon/project/kraak/kraak-xslt/publicatiebladen/staatscourant/stcrt_step2.xsl">
  <x:param name='ns' select="false()"/>

  <x:scenario label='test'>
    <x:scenario label='werkt dit'>
      <x:context><bezwaar>
          <al>Noem in het bezwaarschrift:</al>
          <al nadruk="cur">Vergeet niet te ondertekenen.</al>
        </bezwaar>
      </x:context>
      <x:expect>
        <bezwaar>
          <al>Noem in het bezwaarschrift:</al>
        <al nadruk="cur">Vergeet niet te ondertekenen.</al>
      </bezwaar>
    </x:expect>
    </x:scenario>
  </x:scenario>
</x:description>

Test report showing failure: test report

Can you explain what I am failing to see?

Ruud

ruud
  • 743
  • 13
  • 22
  • 2
    It seems the type of the result (`document-node()`) differs from the type of the expected result (`element()`). I am not sure where in the scenario you have to adapt that, however. – Martin Honnen Nov 14 '19 at 11:52
  • Martin, I used the wrong stylesheet. I have produced a new minimum xsl stylesheet that produces exactly the screenshot (I edited the question). The difference is the use of a variable in the xslt that obviously causes a document node to be returned, making xspec reporting a failure. Probably now you are able to explain what I can do to convert the document-node into an element. – ruud Nov 14 '19 at 13:36
  • yes, if I replace the copy-of by a apply-templates, then the test passes. I use and a second identity transform for this mode. Seems a bit cripple solution. Can it be done more elegantly? – ruud Nov 14 '19 at 13:58
  • 2
    Well, if `` makes the test fail because you return the document node in the variable `content` then of course `` should suffice to return the element inside the document node and have the test pass. Or declare that variable as `...`. – Martin Honnen Nov 14 '19 at 14:08
  • thanks Martin, that is exactly I was looking for. I should be able to accept your comments as answer!! – ruud Nov 14 '19 at 14:14

2 Answers2

2

Because xsl:variable doesn't have @as, your result is a document node. But your x:expect expects an element.

If you want to let your x:expect expect a document node, you need to add select="/" to x:expect. Look for an explanation "If you specify no @select" in XSpec Wiki.

AirQuick
  • 61
  • 3
  • thanks for this answer. I was not aware of the possiblity of a select on the expect element. Very helpful!! – ruud Nov 14 '19 at 14:30
0

If you have run your XSL then bezwaar Element come 2 times and come extra namespace because you have x:context and x:expect in the same element. if you want to x:expect same as x:context then you can try this code.

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:x = "http://www.jenitennison.com/xslt/xspec"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs x">

<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="x:scenario">
    <xsl:apply-templates select="x:scenario/x:context/bezwaar"/>
</xsl:template>
<xsl:template match="bezwaar">
    <xsl:element name="{local-name()}">
        <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
</xsl:template>
<xsl:template match="al">
    <xsl:element name="{local-name()}">
        <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
</xsl:template>
<xsl:template match="@*">
    <xsl:attribute name="{local-name(.)}">
        <xsl:value-of select="."/>
    </xsl:attribute>
</xsl:template>

or if you want bezwaar multiple times then you can comment 1st template match.

Sam
  • 841
  • 1
  • 5
  • 15