Last active
June 5, 2016 12:40
-
-
Save eerohele/728bb94a35fc0644b0c394bdbb840598 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MySpecification extends XsltSpecification(new File("src/test/resources/stylesheets/test.xsl")) { | |
"Simple transformation" >> { | |
applying(<paragraph>foo</paragraph>) yields(<p>foo</p>) | |
} | |
"Set mode and parameters" >> { | |
applying(<paragraph>foo</paragraph>) | |
.withMode("main") | |
.withParameters(tunnel = false)("foo" -> "bar", "baz" -> "quux") | |
.yields(<p>bar, quux</p>) | |
} | |
"Apply a template that returns an atomic value" >> { | |
applying(<anyElement/>).withMode("returns-atomic-value").yields(6) | |
} | |
"Call a function that returns an atomic value" >> { | |
callingFunction("local", "increment", 1).returns(2) | |
} | |
"Call a function that takes an element and returns a document node" >> { | |
callingFunction("local", "wrap-into-foo", parameters = element(<bar/>)).returns(<foo><bar/></foo>) | |
} | |
"Call a function that takes and returns an attribute" >> { | |
callingFunction("local", "rename-to-baz", parameters = attribute("foo" -> "bar")).returns(attribute("baz" -> "quux")) | |
} | |
"Call a function that takes mixed parameters" >> { | |
callingFunction("local", "mix", 1, element(<foo/>), "bar").returns(<foo/>, BigInteger.valueOf(1), "bar") | |
} | |
"Call a named template that returns an atomic value" >> { | |
callingTemplate("sum").withParameters(tunnel = false)("a" -> 1, "b" -> 2).returns(3) | |
} | |
"Apply a template that calls doc()" >> { | |
applying(<include href="b.xml"/>, MockFile("b.xml", <foo/>)).yields(<foo/>) | |
} | |
"<xsl:result-document> creates a file in the transient file system" >> { | |
applying(<paragraph>foo</paragraph>).withMode("result-document") | |
.yieldsNothing and (Fs.hasFile(fileSystem, "foo.xml") must beTrue) | |
}.pendingUntilFixed("https://saxonica.plan.io/issues/2771") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<xsl:stylesheet version="2.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:xs="http://www.w3.org/2001/XMLSchema" | |
xmlns:local="local" | |
exclude-result-prefixes="xs"> | |
<xsl:output method="xml" indent="yes"/> | |
<xsl:function name="local:increment" as="xs:integer"> | |
<xsl:param name="integer" as="xs:integer"/> | |
<xsl:sequence select="$integer + 1"/> | |
</xsl:function> | |
<xsl:function name="local:wrap-into-foo" as="document-node()"> | |
<xsl:param name="el" as="element()"/> | |
<xsl:variable name="returned"> | |
<xsl:element name="foo"> | |
<xsl:sequence select="$el"/> | |
</xsl:element> | |
</xsl:variable> | |
<xsl:sequence select="$returned"/> | |
</xsl:function> | |
<xsl:function name="local:rename-to-baz" as="attribute(baz)"> | |
<xsl:param name="attr" as="attribute(foo)"/> | |
<xsl:variable name="new-attr" as="attribute()"> | |
<xsl:attribute name="baz">quux</xsl:attribute> | |
</xsl:variable> | |
<xsl:sequence select="$new-attr"/> | |
</xsl:function> | |
<xsl:function name="local:mix" as="item()+"> | |
<xsl:param name="int" as="xs:integer"/> | |
<xsl:param name="el" as="element()"/> | |
<xsl:param name="str" as="xs:string"/> | |
<xsl:sequence select="($el, $int, $str)"/> | |
</xsl:function> | |
<xsl:template match="paragraph"> | |
<p> | |
<xsl:apply-templates select="@* | node()"/> | |
</p> | |
</xsl:template> | |
<xsl:template match="paragraph" mode="main"> | |
<xsl:param name="foo"/> | |
<xsl:param name="baz"/> | |
<p> | |
<xsl:value-of select="$foo"/>, <xsl:value-of select="$baz"/> | |
</p> | |
</xsl:template> | |
<xsl:template match="paragraph" mode="result-document"> | |
<!-- | |
<xsl:result-document href="foo.xml"> | |
<p> | |
<xsl:apply-templates select="@* | node()"/> | |
</p> | |
</xsl:result-document> | |
--> | |
</xsl:template> | |
<xsl:template match="*" mode="returns-atomic-value" as="xs:integer"> | |
<xsl:value-of select="sum((1, 2, 3))"/> | |
</xsl:template> | |
<xsl:template name="sum" as="xs:integer"> | |
<xsl:param name="a" as="xs:integer"/> | |
<xsl:param name="b" as="xs:integer"/> | |
<xsl:value-of select="$a + $b"/> | |
</xsl:template> | |
<xsl:template match="include"> | |
<xsl:sequence select="doc(resolve-uri(@href, base-uri()))"/> | |
</xsl:template> | |
<xsl:template match="@* | node()"> | |
<xsl:copy> | |
<xsl:apply-templates select="@* | node()"/> | |
</xsl:copy> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment