Skip to content

Instantly share code, notes, and snippets.

@martin-honnen
Last active December 19, 2024 17:07
Show Gist options
  • Select an option

  • Save martin-honnen/5564ed0897a7e28bd974a96a562fe886 to your computer and use it in GitHub Desktop.

Select an option

Save martin-honnen/5564ed0897a7e28bd974a96a562fe886 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:param name="collection-uri" as="xs:string" select="'./?select=*.xml'"/>
<xsl:output method="xml" indent="yes"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="/" name="xsl:initial-template">
<files>
<xsl:sequence select="collection($collection-uri)"/>
</files>
<xsl:comment>Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} at {current-dateTime()}</xsl:comment>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:param name="collection-uri" as="xs:string" select="'gist:/'"/>
<xsl:output method="xml" indent="yes"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="/" name="xsl:initial-template">
<files>
<xsl:sequence select="uri-collection($collection-uri)"/>
</files>
<xsl:comment>Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} at {current-dateTime()}</xsl:comment>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:param name="collection-uri" as="xs:string" select="'gist:/'"/>
<xsl:output method="xml" indent="yes"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="/" name="xsl:initial-template">
<files>
<uri-collection>{uri-collection($collection-uri)}</uri-collection>
<xsl:sequence select="uri-collection($collection-uri)[ends-with(., '.xml')]!doc(.)"/>
</files>
<xsl:comment>Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} at {current-dateTime()}</xsl:comment>
</xsl:template>
</xsl:stylesheet>
{ "name" : "foo", "data" : [1, 2, 3] }
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method 'adaptive';
declare option output:indent 'yes';
.,
doc('sample1.xml'),
unparsed-text('text-sample1.txt'),
json-doc('json-sample1.json')
import module namespace example1 = 'http://example.com/xquery-examples/module1' at 'xquery-module1.xqm';
declare namespace output = 'http://www.w3.org/2010/xslt-xquery-serialization';
declare option output:method 'adaptive';
declare option output:indent 'yes';
.,
doc('sample1.xml'),
unparsed-text('text-sample1.txt'),
json-doc('json-sample1.json'),
example1:foo()
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:param name="uris" as="xs:string*" select="(1 to 3) ! ('sample' || . || '.xml')"/>
<xsl:output method="xml" indent="yes"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="/" name="xsl:initial-template">
<files>
<xsl:for-each select="$uris ! resolve-uri(., static-base-uri())">
<uri doc-available="{doc-available(.)}">{.}</uri>
</xsl:for-each>
</files>
</xsl:template>
</xsl:stylesheet>
<root>This is sample 1.</root>
<root>This is sample 2.</root>
<root>This is sample 3.</root>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:param name="uris" as="xs:string*" select="(1 to 3) ! ('sample' || . || '.xml')"/>
<xsl:output method="xml" indent="yes"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="/" name="xsl:initial-template">
<files>
<xsl:sequence select="$uris!doc(.)"/>
</files>
<xsl:comment>Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} at {current-dateTime()}</xsl:comment>
</xsl:template>
</xsl:stylesheet>
{"N":"package","version":"30","packageVersion":"1","saxonVersion":"SaxonJS 2.5","target":"JS","targetVersion":"2","name":"TOP-LEVEL","relocatable":"true","buildDateTime":"2023-07-16T11:53:13.908+02:00","ns":"xml=~ xsl=~ xs=~","C":[{"N":"co","id":"0","uniform":"true","binds":"1","C":[{"N":"template","flags":"os","module":"sequence-test1.xsl","slots":"200","name":"Q{http://www.w3.org/1999/XSL/Transform}initial-template","line":"14","expand-text":"true","sType":"*N ","C":[{"N":"sequence","role":"body","sType":"*N ","C":[{"N":"elem","name":"files","sType":"1NE nQ{}files ","nsuri":"","namespaces":"","line":"15","C":[{"N":"forEach","sType":"*ND","ns":"= xml=~ fn=~ xsl=~ xs=~ ","role":"select","line":"16","C":[{"N":"gVarRef","name":"Q{}uris","bSlot":"0"},{"N":"fn","name":"doc","C":[{"N":"dot"}]}]}]},{"N":"comment","sType":"1NC ","C":[{"N":"fn","name":"string-join","role":"select","C":[{"N":"forEach","sType":"*AS ","C":[{"N":"data","sType":"*A ","C":[{"N":"mergeAdj","C":[{"N":"valueOf","sType":"1NT ","C":[{"N":"fn","name":"string-join","C":[{"N":"sequence","sType":"*AS ","C":[{"N":"str","sType":"1AS ","val":"Run with "},{"N":"fn","name":"string-join","sType":"1AS ","C":[{"N":"convert","type":"AS*","from":"AZ","to":"AS","C":[{"N":"data","C":[{"N":"mergeAdj","sType":"1AS","C":[{"N":"fn","name":"system-property","sType":"1AS","ns":"= xml=~ fn=~ xsl=~ xs=~ ","line":"18","C":[{"N":"str","val":"xsl:product-name"}]}]}]}]},{"N":"str","sType":"1AS ","val":" "}]},{"N":"str","sType":"1AS ","val":" "},{"N":"fn","name":"string-join","sType":"1AS ","C":[{"N":"convert","type":"AS*","from":"AZ","to":"AS","C":[{"N":"data","C":[{"N":"mergeAdj","sType":"1AS","C":[{"N":"fn","name":"system-property","sType":"1AS","ns":"= xml=~ fn=~ xsl=~ xs=~ ","line":"18","C":[{"N":"str","val":"xsl:product-version"}]}]}]}]},{"N":"str","sType":"1AS ","val":" "}]},{"N":"str","sType":"1AS ","val":" at "},{"N":"fn","name":"string-join","sType":"1AS ","C":[{"N":"convert","type":"AS*","from":"AZ","to":"AS","C":[{"N":"data","C":[{"N":"mergeAdj","sType":"1AMP","C":[{"N":"fn","name":"current-dateTime","sType":"1AMP","ns":"= xml=~ fn=~ xsl=~ xs=~ ","line":"18"}]}]}]},{"N":"str","sType":"1AS ","val":" "}]}]},{"N":"str","sType":"1AS ","val":""}]}]}]}]},{"N":"fn","name":"string","sType":"1AS ","C":[{"N":"dot"}]}]},{"N":"str","sType":"1AS ","val":" "}]}]}]}]}]},{"N":"co","binds":"","id":"1","vis":"PUBLIC","ex:uniform":"true","C":[{"N":"globalParam","name":"Q{}uris","sType":"*AS ","slots":"200","module":"sequence-test1.xsl","as":"*AS ","ns":"xml=~ xsl=~ xs=~","C":[{"N":"forEach","sType":"*AS","ns":"= xml=~ fn=~ xsl=~ xs=~ ","role":"select","line":"8","C":[{"N":"range","from":"1","to":"3"},{"N":"fn","name":"concat","C":[{"N":"str","val":"sample"},{"N":"dot"},{"N":"str","val":".xml"}]}]}]}]},{"N":"co","id":"2","binds":"1","C":[{"N":"mode","onNo":"SC","flags":"","patternSlots":"0","prec":"","C":[{"N":"templateRule","rank":"0","prec":"0","seq":"0","ns":"xml=~ xsl=~ xs=~","minImp":"0","flags":"s","slots":"200","line":"14","module":"sequence-test1.xsl","expand-text":"true","match":"/","prio":"-0.5","matches":"ND","C":[{"N":"p.nodeTest","role":"match","test":"ND","sType":"1ND","ns":"= xml=~ fn=~ xsl=~ xs=~ "},{"N":"sequence","role":"action","sType":"*N ","C":[{"N":"elem","name":"files","sType":"1NE nQ{}files ","nsuri":"","namespaces":"","line":"15","C":[{"N":"forEach","sType":"*ND","ns":"= xml=~ fn=~ xsl=~ xs=~ ","role":"select","line":"16","C":[{"N":"gVarRef","name":"Q{}uris","bSlot":"0"},{"N":"fn","name":"doc","C":[{"N":"dot"}]}]}]},{"N":"comment","sType":"1NC ","C":[{"N":"fn","name":"string-join","role":"select","C":[{"N":"forEach","sType":"*AS ","C":[{"N":"data","sType":"*A ","C":[{"N":"mergeAdj","C":[{"N":"valueOf","sType":"1NT ","C":[{"N":"fn","name":"string-join","C":[{"N":"sequence","sType":"*AS ","C":[{"N":"str","sType":"1AS ","val":"Run with "},{"N":"fn","name":"string-join","sType":"1AS ","C":[{"N":"convert","type":"AS*","from":"AZ","to":"AS","C":[{"N":"data","C":[{"N":"mergeAdj","sType":"1AS","C":[{"N":"fn","name":"system-property","sType":"1AS","ns":"= xml=~ fn=~ xsl=~ xs=~ ","line":"18","C":[{"N":"str","val":"xsl:product-name"}]}]}]}]},{"N":"str","sType":"1AS ","val":" "}]},{"N":"str","sType":"1AS ","val":" "},{"N":"fn","name":"string-join","sType":"1AS ","C":[{"N":"convert","type":"AS*","from":"AZ","to":"AS","C":[{"N":"data","C":[{"N":"mergeAdj","sType":"1AS","C":[{"N":"fn","name":"system-property","sType":"1AS","ns":"= xml=~ fn=~ xsl=~ xs=~ ","line":"18","C":[{"N":"str","val":"xsl:product-version"}]}]}]}]},{"N":"str","sType":"1AS ","val":" "}]},{"N":"str","sType":"1AS ","val":" at "},{"N":"fn","name":"string-join","sType":"1AS ","C":[{"N":"convert","type":"AS*","from":"AZ","to":"AS","C":[{"N":"data","C":[{"N":"mergeAdj","sType":"1AMP","C":[{"N":"fn","name":"current-dateTime","sType":"1AMP","ns":"= xml=~ fn=~ xsl=~ xs=~ ","line":"18"}]}]}]},{"N":"str","sType":"1AS ","val":" "}]}]},{"N":"str","sType":"1AS ","val":""}]}]}]}]},{"N":"fn","name":"string","sType":"1AS ","C":[{"N":"dot"}]}]},{"N":"str","sType":"1AS ","val":" "}]}]}]}]}]}]},{"N":"overridden"},{"N":"output","C":[{"N":"property","name":"Q{http://saxon.sf.net/}stylesheet-version","value":"30"},{"N":"property","name":"method","value":"xml"},{"N":"property","name":"indent","value":"yes"}]},{"N":"decimalFormat"}],"Σ":"5307934e"}
This is a test.
This is a test.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:param name="relative-uri" as="xs:string" select="'text-sample1.txt'"/>
<xsl:param name="gist-uri" as="xs:string" select="'gist:/text-sample1.txt'"/>
<xsl:output method="xml" indent="yes"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="/" name="xsl:initial-template">
<files>
<file>
<xsl:sequence select="unparsed-text($relative-uri)"/>
</file>
<file>
<xsl:sequence select="unparsed-text($gist-uri)"/>
</file>
</files>
<xsl:comment>Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} at {current-dateTime()}</xsl:comment>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:param name="uri" as="xs:string" select="'text-sample1.txt'"/>
<xsl:output method="xml" indent="yes"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="/" name="xsl:initial-template">
<file>
<xsl:sequence select="unparsed-text($uri)"/>
</file>
<xsl:comment>Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} at {current-dateTime()}</xsl:comment>
</xsl:template>
</xsl:stylesheet>
{"N":"package","version":"30","packageVersion":"1","saxonVersion":"SaxonJS 2.5","target":"JS","targetVersion":"2","name":"TOP-LEVEL","relocatable":"true","buildDateTime":"2023-07-16T11:52:54.239+02:00","ns":"xml=~ xsl=~ xs=~","C":[{"N":"co","id":"0","uniform":"true","binds":"1","C":[{"N":"template","flags":"os","module":"unparsed-text-test1.xsl","slots":"200","name":"Q{http://www.w3.org/1999/XSL/Transform}initial-template","line":"14","expand-text":"true","sType":"*N ","C":[{"N":"sequence","role":"body","sType":"*N ","C":[{"N":"elem","name":"file","sType":"1NE nQ{}file ","nsuri":"","namespaces":"","line":"15","C":[{"N":"fn","name":"unparsed-text","sType":"?AS","ns":"= xml=~ fn=~ xsl=~ xs=~ ","role":"select","line":"16","C":[{"N":"gVarRef","name":"Q{}uri","bSlot":"0"}]}]},{"N":"comment","sType":"1NC ","C":[{"N":"fn","name":"string-join","role":"select","C":[{"N":"forEach","sType":"*AS ","C":[{"N":"data","sType":"*A ","C":[{"N":"mergeAdj","C":[{"N":"valueOf","sType":"1NT ","C":[{"N":"fn","name":"string-join","C":[{"N":"sequence","sType":"*AS ","C":[{"N":"str","sType":"1AS ","val":"Run with "},{"N":"fn","name":"string-join","sType":"1AS ","C":[{"N":"convert","type":"AS*","from":"AZ","to":"AS","C":[{"N":"data","C":[{"N":"mergeAdj","sType":"1AS","C":[{"N":"fn","name":"system-property","sType":"1AS","ns":"= xml=~ fn=~ xsl=~ xs=~ ","line":"18","C":[{"N":"str","val":"xsl:product-name"}]}]}]}]},{"N":"str","sType":"1AS ","val":" "}]},{"N":"str","sType":"1AS ","val":" "},{"N":"fn","name":"string-join","sType":"1AS ","C":[{"N":"convert","type":"AS*","from":"AZ","to":"AS","C":[{"N":"data","C":[{"N":"mergeAdj","sType":"1AS","C":[{"N":"fn","name":"system-property","sType":"1AS","ns":"= xml=~ fn=~ xsl=~ xs=~ ","line":"18","C":[{"N":"str","val":"xsl:product-version"}]}]}]}]},{"N":"str","sType":"1AS ","val":" "}]},{"N":"str","sType":"1AS ","val":" at "},{"N":"fn","name":"string-join","sType":"1AS ","C":[{"N":"convert","type":"AS*","from":"AZ","to":"AS","C":[{"N":"data","C":[{"N":"mergeAdj","sType":"1AMP","C":[{"N":"fn","name":"current-dateTime","sType":"1AMP","ns":"= xml=~ fn=~ xsl=~ xs=~ ","line":"18"}]}]}]},{"N":"str","sType":"1AS ","val":" "}]}]},{"N":"str","sType":"1AS ","val":""}]}]}]}]},{"N":"fn","name":"string","sType":"1AS ","C":[{"N":"dot"}]}]},{"N":"str","sType":"1AS ","val":" "}]}]}]}]}]},{"N":"co","binds":"","id":"1","vis":"PUBLIC","ex:uniform":"true","C":[{"N":"globalParam","name":"Q{}uri","sType":"AS ","slots":"200","module":"unparsed-text-test1.xsl","as":"AS ","ns":"xml=~ xsl=~ xs=~","C":[{"N":"str","val":"text-sample1.txt","sType":"1AS","ns":"= xml=~ fn=~ xsl=~ xs=~ ","role":"select","line":"8"}]}]},{"N":"co","id":"2","binds":"1","C":[{"N":"mode","onNo":"SC","flags":"","patternSlots":"0","prec":"","C":[{"N":"templateRule","rank":"0","prec":"0","seq":"0","ns":"xml=~ xsl=~ xs=~","minImp":"0","flags":"s","slots":"200","line":"14","module":"unparsed-text-test1.xsl","expand-text":"true","match":"/","prio":"-0.5","matches":"ND","C":[{"N":"p.nodeTest","role":"match","test":"ND","sType":"1ND","ns":"= xml=~ fn=~ xsl=~ xs=~ "},{"N":"sequence","role":"action","sType":"*N ","C":[{"N":"elem","name":"file","sType":"1NE nQ{}file ","nsuri":"","namespaces":"","line":"15","C":[{"N":"fn","name":"unparsed-text","sType":"?AS","ns":"= xml=~ fn=~ xsl=~ xs=~ ","role":"select","line":"16","C":[{"N":"gVarRef","name":"Q{}uri","bSlot":"0"}]}]},{"N":"comment","sType":"1NC ","C":[{"N":"fn","name":"string-join","role":"select","C":[{"N":"forEach","sType":"*AS ","C":[{"N":"data","sType":"*A ","C":[{"N":"mergeAdj","C":[{"N":"valueOf","sType":"1NT ","C":[{"N":"fn","name":"string-join","C":[{"N":"sequence","sType":"*AS ","C":[{"N":"str","sType":"1AS ","val":"Run with "},{"N":"fn","name":"string-join","sType":"1AS ","C":[{"N":"convert","type":"AS*","from":"AZ","to":"AS","C":[{"N":"data","C":[{"N":"mergeAdj","sType":"1AS","C":[{"N":"fn","name":"system-property","sType":"1AS","ns":"= xml=~ fn=~ xsl=~ xs=~ ","line":"18","C":[{"N":"str","val":"xsl:product-name"}]}]}]}]},{"N":"str","sType":"1AS ","val":" "}]},{"N":"str","sType":"1AS ","val":" "},{"N":"fn","name":"string-join","sType":"1AS ","C":[{"N":"convert","type":"AS*","from":"AZ","to":"AS","C":[{"N":"data","C":[{"N":"mergeAdj","sType":"1AS","C":[{"N":"fn","name":"system-property","sType":"1AS","ns":"= xml=~ fn=~ xsl=~ xs=~ ","line":"18","C":[{"N":"str","val":"xsl:product-version"}]}]}]}]},{"N":"str","sType":"1AS ","val":" "}]},{"N":"str","sType":"1AS ","val":" at "},{"N":"fn","name":"string-join","sType":"1AS ","C":[{"N":"convert","type":"AS*","from":"AZ","to":"AS","C":[{"N":"data","C":[{"N":"mergeAdj","sType":"1AMP","C":[{"N":"fn","name":"current-dateTime","sType":"1AMP","ns":"= xml=~ fn=~ xsl=~ xs=~ ","line":"18"}]}]}]},{"N":"str","sType":"1AS ","val":" "}]}]},{"N":"str","sType":"1AS ","val":""}]}]}]}]},{"N":"fn","name":"string","sType":"1AS ","C":[{"N":"dot"}]}]},{"N":"str","sType":"1AS ","val":" "}]}]}]}]}]}]},{"N":"overridden"},{"N":"output","C":[{"N":"property","name":"Q{http://saxon.sf.net/}stylesheet-version","value":"30"},{"N":"property","name":"method","value":"xml"},{"N":"property","name":"indent","value":"yes"}]},{"N":"decimalFormat"}],"Σ":"79afbd62"}
.,
doc('sample2.xml'),
unparsed-text('text-sample1.txt'),
json-doc('json-sample1.json')
module namespace example1 = 'http://example.com/xquery-examples/module1';
declare function example1:foo() as node() {
doc('sample2.xml')
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment