0

I'm writing a program that uses XSLT and need to test the contents of a result-document call in Xspec. In the example below, I would like to test the contents of result.xml. If this is possible, how do you do this?

XML: test.xml

<?xml version="1.0" encoding="UTF-8"?>
<root></root>

XSLT: result-document.xsl

<?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"
    version="2.0">
    <xsl:template match="/root">
        <xsl:result-document href="result.xml">
            <my-result></my-result>
        </xsl:result-document>
    </xsl:template>
</xsl:stylesheet>

XSpec:

<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="result-document.xsl">
    <x:scenario label="Test result document">
        <x:context href="test.xml"></x:context>
        <!-- How do you test the result.xml file here? -->
        <x:expect label="test result">
            <my-result></my-result>
        </x:expect>
    </x:scenario>
</x:description>
potame
  • 7,597
  • 4
  • 26
  • 33
user1428945
  • 339
  • 1
  • 13

1 Answers1

1

I was looking for the same answer, but I suspect this is an inherent limitation in how XSpec is implemented.

I suspect the work-around is to have one untestable template that uses the result-document, then use a match or call template within the result-document that can be tested:

XSLT

<xsl:template match="/root">
    <xsl:result-document href="result.xml">
        <xsl:call-template name="my-result"/>
    </xsl:result-document>
</xsl:template>

<xsl:template name="my-result">
  <!-- content -->
</xsl:template>

XSPEC

<x:scenario label="when calling my-result">
  <x:call template="my-result"/>
  <x:expect label="test something" pending="add your tests here"/>
</x:scenario>

So you can't really test that the result documents are being made in the right way, but you can check their results.

Note that XSPEC won't literally "test the contents of result.xml"; just the behaviour of the XSLT on the inputs that you specify in the XSPEC itself.

Tom Hillman
  • 327
  • 1
  • 10