Using XSpec with xsl:result-document in XSLT file

88 views
Skip to first unread message

Jenny Sherman

unread,
Aug 22, 2019, 4:59:48 PM8/22/19
to XSpec
hi

I wrote some very simple XSLT and associated XSpec tests and everything worked fine.

My spec then changed to specify the filename of the output xml file within the XSLT. I used xsl:result-document to do this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  exclude-result-prefixes="xs"
  version="2.0">

  <xsl:template match="/">
    <xsl:result-document href="{//Rendition/@ISBN}.xml">
    <Extract>
      <xsl:apply-templates select="//Series[not(@Type='Sub Series')]"/>
      <xsl:apply-templates select="//Series[@Type='Sub Series']"/>
      <xsl:apply-templates select="//Edition"/>
    </Extract>
    </xsl:result-document>
  </xsl:template>
  ...
</xsl:stylesheet>

My sample files are still output correctly, but unfortunately my XSpec now fails for every test as the result output is empty. Example snippet from XSpec:

<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="../../Extract.xsl">
    <x:scenario label="Series">
      <x:context href="XML-Samples/file.xml"/>
      <x:expect label="if Series information exists, include in extract retaining 'ID' attribute" test="exists(/GenericXMLExtract/Series[not(@Type)][@ID='15427'])"/>
      <x:expect label="if Series has EISSN and ISSN information, retain as attributes" test="exists(/GenericXMLExtract/Series[@ID='15427'][@EISSN='2522-8609'][@ISSN='2522-8595'])"/>
      ...
    </x:scenario>
</x:description>

Can anyone tell me how I can update my XSLT and/or my XSpec so that the result is not empty and the tests will pass?


AirQuick

unread,
Aug 23, 2019, 1:29:46 PM8/23/19
to xspec...@googlegroups.com
The current XSpec implementation doesn't work with xsl:result-document.

A quick workaround would be encapsulating its sequence constructor in a named template

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  exclude-result-prefixes="xs"
  version="2.0">

  <xsl:template match="/">
    <xsl:result-document href="{//Rendition/@ISBN}.xml">
      <xsl:call-template name="document-node-handler" />
    </xsl:result-document>
  </xsl:template>

  <xsl:template name="document-node-handler">
    <Extract>
      <xsl:apply-templates select="//Series[not(@Type='Sub Series')]"/>
      ...
    </Extract>
  </xsl:template>

</xsl:stylesheet>

and testing it

<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" stylesheet="../../Extract.xsl">
    <x:scenario label="Series">
      <x:context href="XML-Samples/file.xml"/>
      <x:call template="document-node-handler"/>
      <x:expect label="if Series information exists, include in extract retaining 'ID' attribute" test="exists(/GenericXMLExtract/Series[not(@Type)][@ID='15427'])"/>
      ...
    </x:scenario>
</x:description>

Just my quick thought.
--
You received this message because you are subscribed to the Google Groups "XSpec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xspec-users...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages