XSpec unit tests failing on unusual differences

Here should go questions about transforming XML with XSLT and FOP.
Crispness
Posts: 5

XSpec unit tests failing on unusual differences

Tue Aug 18, 2015 4:22 pm

Hi
I am using OxygenXML to write unit tests for some XSLT stylesheets I am working on.

Two of my tests is failing but I can't see why.

I have separated the failing tests into their own unit test doc and stylesheet

The xspec doc is as follows

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="email-test.xsl">
    <x:scenario label="Testing email processing and white space management">
        <x:scenario label="email1">
            <x:context><email username="info.london" edomname="croports.com"/></x:context>
            <x:expect label="inline items"><a href="mailto:info.london@croports.com">info.london@croports.com</a> </x:expect>
        </x:scenario>
        <x:scenario label="email2">
            <x:context><email address="info.london@croports.com"/></x:context>
            <x:expect label="inline items"><a href="mailto:info.london@croports.com">info.london@croports.com</a></x:expect>
        </x:scenario>
    </x:scenario>
</x:description>

and the xslt as follows

Code: Select all

<?xml version="1.0"?>
<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
   exclude-result-prefixes="xd"
   version="2.0">

   <xsl:template match="email[@edomname]">
      <xsl:variable name="email-addr" select="concat(@username,'@',@edomname)"/>
      <a href="{concat('mailto:',$email-addr)}"><xsl:value-of select="$email-addr"/></a><xsl:text> </xsl:text>
   </xsl:template>
   
   <xsl:template match="email[@address]">
      <xsl:variable name="email-addr" select="@address"/>
      <a href="{concat('mailto:',$email-addr)}"><xsl:value-of select="$email-addr"/></a><xsl:text> </xsl:text>
   </xsl:template>

</xsl:stylesheet>


The tests were originally part of a much larger test suite as was the xslt but I have simplified it back as much as possible for debugging purposes.

The results of running the xspec are slightly strange - see screenshot
Image
It seems that the xspec processor is adding an addition fullstop at the end of the output

Can anyone either replicate this? Or explain what I'm doing wrong?

Thanks
radu_pisoi
Posts: 334
Location: Craiova

Re: XSpec unit tests failing on unusual differences

Wed Aug 19, 2015 10:52 am

Hi,

The difference between the expected result written in the XSpec file and the XML fragment produced by the XSLT transformation consists of the missing whitespace after the a element in the expected result.

So, both templates from the XSLT stylesheet emit a white-space after the a element with the xsl:text instruction. In the XSpec file, to signal that the white-space after the a element is significant you have to use xml:space="preserve" attribute on the x:expect element.

Code: Select all

<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="email-test.xsl">
    <x:scenario label="Testing email processing and white space management">
        <x:scenario label="email1">
            <x:context><email username="info.london" edomname="croports.com"/></x:context>
            <x:expect label="inline items" xml:space="preserve"><a href="mailto:info.london@croports.com">info.london@croports.com</a> </x:expect>
        </x:scenario>
        <x:scenario label="email2">
            <x:context><email address="info.london@croports.com"/></x:context>
            <x:expect label="inline items" xml:space="preserve"><a href="mailto:info.london@croports.com">info.london@croports.com</a> </x:expect>
        </x:scenario>
    </x:scenario>
</x:description>
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Crispness
Posts: 5

Re: XSpec unit tests failing on unusual differences

Thu Aug 27, 2015 4:01 pm

Is there a way to tell it to ignore whitespace during the tests?
radu_pisoi
Posts: 334
Location: Craiova

Re: XSpec unit tests failing on unusual differences

Fri Aug 28, 2015 9:55 am

No, there is no particular attribute to signal that whitespaces should be preserved other than 'xml:space="preserve"'.
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 1 guest