Skip to content

Commit

Permalink
Sample code for "Overriding Global XSLT Variables in XSpec, Part 3" (#59
Browse files Browse the repository at this point in the history
)

* Rename XSpec file for better alignment with Part 3

* Sample code for "Overriding Global XSLT Variables in XSpec, Part 3"
  • Loading branch information
galtm authored Dec 19, 2024
1 parent 0e150a1 commit acd30c9
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Each post corresponds to a [subfolder under `src/`](https://github.com/galtm/xsp
* [My XML Content in XSpec Causes an Error](https://github.com/galtm/xspectacles/tree/main/src/xml-content-error)
* [One-or-More Ways to Foil Empty-Sequence Surprises in XSpec](https://github.com/galtm/xspectacles/tree/main/src/one-or-more)
* [Overriding Global XSLT Variables in XSpec, Part 1](https://github.com/galtm/xspectacles/tree/main/src/override-global-var-part1)
* **(NEW!)** [Overriding Global XSLT Variables in XSpec, Part 2](https://github.com/galtm/xspectacles/tree/main/src/override-global-var-part2)
* [Overriding Global XSLT Variables in XSpec, Part 2](https://github.com/galtm/xspectacles/tree/main/src/override-global-var-part2)
* **(NEW!)** [Overriding Global XSLT Variables in XSpec, Part 3](https://github.com/galtm/xspectacles/tree/main/src/override-global-var-part3)
* [Saying "Almost Valid" or "Beyond Valid" in XSpec Tests for Schematron](https://github.com/galtm/xspectacles/tree/main/src/almost-valid)
* [Saying "Not Yet" in XSpec](https://github.com/galtm/xspectacles/tree/main/src/pending)
* [Saying "Whatever" in XSpec: How, Why, When](https://github.com/galtm/xspectacles/tree/main/src/three-dots)
Expand Down
2 changes: 1 addition & 1 deletion src/override-global-var-part2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Example files combining `run-as="external"` with `xsl:stylesheet/xsl:variable`:

- `production-stylesheet.xsl`
- `test-only-stylesheet.xsl`
- `test-external-global.xspec`
- `external_override-in-test-only-stylesheet.xspec`

#### Links to Topic
[Overriding Global XSLT Variables in XSpec, Part 2](https://medium.com/@xspectacles/overriding-global-xslt-variables-in-xspec-part-2-31829081f982)
11 changes: 11 additions & 0 deletions src/override-global-var-part3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Sample code for "Overriding Global XSLT Variables in XSpec, Part 3"

Example files combining `run-as="external"` with `xsl:package/xsl:variable`:

- `production-pkg/production-pkg.xsl`
- `test-only-pkg/test-only-pkg.xsl`
- `config.xml`
- `external_override-in-test-only-pkg.xspec`

#### Links to Topic
[Overriding Global XSLT Variables in XSpec, Part 3](https://medium.com/@xspectacles/overriding-global-xslt-variables-in-xspec-part-3-545205cef963)
16 changes: 16 additions & 0 deletions src/override-global-var-part3/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Sample Code for "Overriding Global XSLT Variables in XSpec, Part 3"
https://medium.com/@xspectacles/overriding-global-xslt-variables-in-xspec-part-3-545205cef963
-->
<configuration xmlns="http://saxon.sf.net/ns/configuration">
<xsltPackages>
<package name="urn:x-xspectacles:pkgs:production-pkg"
version="1.0"
sourceLocation="production-pkg/production-pkg.xsl"/>
<package name="urn:x-xspectacles:pkgs:test-only-pkg"
version="1.0"
sourceLocation="test-only-pkg/test-only-pkg.xsl"/>
</xsltPackages>
</configuration>
<!-- Copyright © 2024 by Amanda Galtman. -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" ?>
<x:description run-as="external"
stylesheet="test-only-pkg/test-only-pkg.xsl"
xslt-version="3.0"
xmlns:x="http://www.jenitennison.com/xslt/xspec">

<!--
Sample Code for "Overriding Global XSLT Variables in XSpec, Part 3"
https://medium.com/@xspectacles/overriding-global-xslt-variables-in-xspec-part-3-545205cef963
-->

<x:variable name="x:saxon-config" href="config.xml"/>
<x:scenario>
<x:label>
Test-only package overrides global xsl:variable as xsl:param
during external transformation to test an XSLT package
</x:label>
<x:scenario label="With x:param, template uses">
<x:param name="my-param" select="'from x:param'"/>
<x:param name="data-file-name" select="'test-data1.xml'"/>
<x:call template="show-values-of-globals"/>
<x:expect label="the provided values"
select="('from x:param', 'test-data1.xml')"/>
</x:scenario>
<x:scenario label="Without x:param, template uses">
<x:call template="show-values-of-globals"/>
<x:expect label="values from production and xsl:override"
select="('from production', 'test-data-from-override.xml')"/>
</x:scenario>
</x:scenario>
</x:description>
<!-- Copyright © 2024 by Amanda Galtman. -->
22 changes: 22 additions & 0 deletions src/override-global-var-part3/production-pkg/production-pkg.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:package name="urn:x-xspectacles:pkgs:production-pkg"
package-version="1.0" version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!--
Sample Code for "Overriding Global XSLT Variables in XSpec, Part 3"
https://medium.com/@xspectacles/overriding-global-xslt-variables-in-xspec-part-3-545205cef963
-->

<xsl:param name="my-param" as="xs:string"
select="'from production'"/>
<xsl:variable name="data-file-name" as="xs:string"
select="'production.xml'" visibility="public"/>

<xsl:template name="show-values-of-globals" visibility="public">
<xsl:sequence select="($my-param, $data-file-name)"/>
</xsl:template>

</xsl:package>
<!-- Copyright © 2024 by Amanda Galtman. -->
24 changes: 24 additions & 0 deletions src/override-global-var-part3/test-only-pkg/test-only-pkg.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:package name="urn:x-xspectacles:pkgs:test-only-pkg"
package-version="1.0" version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!--
Sample Code for "Overriding Global XSLT Variables in XSpec, Part 3"
https://medium.com/@xspectacles/overriding-global-xslt-variables-in-xspec-part-3-545205cef963
-->

<xsl:use-package name="urn:x-xspectacles:pkgs:production-pkg"
version="1.0">
<xsl:accept component="template" names="show-values-of-globals"
visibility="public"/>
<xsl:override>
<!-- Override xsl:variable with xsl:param -->
<xsl:param name="data-file-name" as="xs:string"
select="'test-data-from-override.xml'"/>
</xsl:override>
</xsl:use-package>

</xsl:package>
<!-- Copyright © 2024 by Amanda Galtman. -->

0 comments on commit acd30c9

Please sign in to comment.