Local variables/parameters in XSpec

67 views
Skip to first unread message

Aaron L

unread,
Oct 25, 2022, 2:09:25 PM10/25/22
to XSpec
I'm trying to better understand local variables/parameters in XSpec.

My XSL adds the attribute 'chunk="to-content"' to a bookmap element if the global parameter 'output-format' has value "pdf".

I thought the below would pass testing for both scenarios, by having the output-format parameter inside the first context element, but the first scenario fails. It also fails if I use a variable inside the scenario.

<!-- Fails -->
<x:scenario label="PDF output">
    <x:context>
        <x:param name="output-format" select="'pdf'" as="xs:string"/>
        <bookmap/>
    </x:context>
    <x:expect label="Chunk to-content">
        <bookmap chunk="to-content"/>
    </x:expect>
</x:scenario>

<!-- Passes -->
<x:scenario label="Other output">
    <x:context>
        <bookmap/>
    </x:context>
    <x:expect label="No chunking">
        <bookmap/>
    </x:expect>
</x:scenario>

If I use a global variable or parameter, then the first scenario passes, but of course the second fails.

<x:param name="output-format" select="'pdf'" as="xs:string"/>
<!-- Passes -->    
<x:scenario label="PDF output">
    <x:context>        
        <bookmap/>
    </x:context>
    <x:expect label="Chunk to-content">
        <bookmap chunk="to-content"/>
    </x:expect>
</x:scenario>

<!-- Fails -->
<x:scenario label="Other output">
    <x:context>
        <bookmap/>
    </x:context>
    <x:expect label="No chunking">
        <bookmap/>
    </x:expect>
</x:scenario>

I have multiple global parameters and variables and I would like to test the different combinations without requiring a separate test file for each. Is this possible?

AirQuick

unread,
Oct 27, 2022, 12:56:04 PM10/27/22
to xspec...@googlegroups.com
x:context/x:param is compiled into xsl:apply-templates/xsl:with-param. So it doesn't test global XSLT parameters (xsl:stylesheet/xsl:param). It tests xsl:template/xsl:param of your template for the current context item.


Testing different scenarios with different global XSLT parameters is possible, when an experimental feature of XSpec is enabled by setting x:description/@run-as = "external". Scenario-level global XSLT parameters are set by x:scenario/x:param. Your XSpec would look like this:

<x:description run-as="external" ...>
<x:scenario label="PDF output">
<x:param name="output-format" select="'pdf'" as="xs:string"/>
<x:context>
<bookmap/>
</x:context>
<x:expect label="Chunk to-content">
<bookmap chunk="to-content"/>
</x:expect>
</x:scenario>

<x:scenario label="Other output">
<x:context>
<bookmap/>
</x:context>
<x:expect label="No chunking">
<bookmap/>
</x:expect>
</x:scenario>
</x:description>

But do not expect @run-as="external" to work universally better than the classic XSpec. Its limitations and some surprising effects on the global context item are noted in https://github.com/xspec/xspec/wiki/External-Transformation .


Hope this helps,
AirQuick

Aaron L

unread,
Dec 24, 2022, 6:19:02 AM12/24/22
to XSpec
Great, thanks for the information and sorry for the late reply!
Reply all
Reply to author
Forward
0 new messages