Skip to content

Commit

Permalink
test(xslt): illustrate existing XSpec reaction to XSLT default-mode (x…
Browse files Browse the repository at this point in the history
…spec#1684)

* Illustrate existing XSpec reaction to XSLT @default-mode

* Rename runas=external tests
  • Loading branch information
galtm committed Apr 26, 2023
1 parent bd6790a commit 914d038
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/default-mode-included.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
default-mode="implicit-default-mode"
exclude-result-prefixes="xs"
version="3.0">

<xsl:template match="*" as="element(no-explicit-mode)">
<no-explicit-mode/>
</xsl:template>

<xsl:template match="*" as="element(unnamed-mode)"
mode="#unnamed" name="unnamed-mode-template">
<unnamed-mode/>
</xsl:template>

</xsl:stylesheet>
39 changes: 39 additions & 0 deletions test/default-mode-parent-runas-imported.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description
xmlns:x="http://www.jenitennison.com/xslt/xspec"
run-as="import"
stylesheet="default-mode-parent.xsl"
xslt-version="3.0">

<x:scenario label="x:context[not(@mode)]">
<x:context>
<element/>
</x:context>
<x:expect>
<x:label>Uses xsl:template[@mode='#unnamed']. When run-as='import', XSLT default-mode has no effect here.</x:label>
<unnamed-mode/>
</x:expect>
</x:scenario>

<x:scenario label="x:context/@mode='implicit-default-mode'">
<x:context mode="implicit-default-mode">
<element/>
</x:context>
<x:expect>
<x:label>Uses xsl:template[not(@mode)], to which XSLT @default-mode applies</x:label>
<no-explicit-mode/>
</x:expect>
</x:scenario>

<x:scenario label="x:call by name, to template with mode='#unnamed'">
<x:context>
<element/>
</x:context>
<x:call template="unnamed-mode-template"/>
<x:expect>
<x:label>Alternate way to reach xsl:template[@mode='#unnamed']</x:label>
<unnamed-mode/>
</x:expect>
</x:scenario>

</x:description>
6 changes: 6 additions & 0 deletions test/default-mode-parent.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0">
<xsl:include href="default-mode-included.xsl"/>
</xsl:stylesheet>
39 changes: 39 additions & 0 deletions test/external_default-mode-included-runas.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description
xmlns:x="http://www.jenitennison.com/xslt/xspec"
run-as="external"
stylesheet="default-mode-included.xsl"
xslt-version="3.0">

<x:scenario label="x:context[not(@mode)]">
<x:context>
<element/>
</x:context>
<x:expect>
<x:label>Uses xsl:template[not(@mode)]. transform() uses XSLT @default-mode as initial mode.</x:label>
<no-explicit-mode/>
</x:expect>
</x:scenario>

<x:scenario label="x:context/@mode='implicit-default-mode'">
<x:context mode="implicit-default-mode">
<element/>
</x:context>
<x:expect>
<x:label>Uses xsl:template[not(@mode)], to which XSLT @default-mode applies. XSpec passes x:context/@mode to transform() as initial mode.</x:label>
<no-explicit-mode/>
</x:expect>
</x:scenario>

<x:scenario label="x:call by name, to template with mode='#unnamed'">
<x:context>
<element/>
</x:context>
<x:call template="unnamed-mode-template"/>
<x:expect>
<x:label>A way to reach xsl:template[@mode='#unnamed'] despite transform() using XSLT @default-mode as initial mode.</x:label>
<unnamed-mode/>
</x:expect>
</x:scenario>

</x:description>
39 changes: 39 additions & 0 deletions test/external_default-mode-parent.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description
xmlns:x="http://www.jenitennison.com/xslt/xspec"
run-as="external"
stylesheet="default-mode-parent.xsl"
xslt-version="3.0">

<x:scenario label="x:context[not(@mode)]">
<x:context>
<element/>
</x:context>
<x:expect>
<x:label>Uses xsl:template[@mode='#unnamed']. Parent XSLT has no @default-mode, so transform() defaults to unnamed mode.</x:label>
<unnamed-mode/>
</x:expect>
</x:scenario>

<x:scenario label="x:context/@mode='implicit-default-mode'">
<x:context mode="implicit-default-mode">
<element/>
</x:context>
<x:expect>
<x:label>Uses xsl:template[not(@mode)], to which XSLT @default-mode applies. XSpec passes x:context/@mode to transform() as initial mode.</x:label>
<no-explicit-mode/>
</x:expect>
</x:scenario>

<x:scenario label="x:call by name, to template with mode='#unnamed'">
<x:context>
<element/>
</x:context>
<x:call template="unnamed-mode-template"/>
<x:expect>
<x:label>Alternate way to reach xsl:template[@mode='#unnamed']</x:label>
<unnamed-mode/>
</x:expect>
</x:scenario>

</x:description>

0 comments on commit 914d038

Please sign in to comment.