Skip to content

Instantly share code, notes, and snippets.

@nine9ths
Last active December 10, 2015 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nine9ths/4402113 to your computer and use it in GitHub Desktop.
Save nine9ths/4402113 to your computer and use it in GitHub Desktop.
XSLT 3.0 stylesheet for Saxon to create a saxon catalog file for collections
<xsl:stylesheet
version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:file="java:java.io.File"
xmlns:jt="http://saxon.sf.net/java-type"
exclude-result-prefixes="xs file jt">
<xsl:param name="directory"/>
<xsl:output indent="yes"/>
<xsl:mode name="recurse" on-no-match="deep-skip"/>
<xsl:mode name="output" on-no-match="deep-skip"/>
<xsl:template match="/">
<collection>
<xsl:apply-templates mode="recurse" select="file:new(resolve-uri($directory))"/>
</collection>
</xsl:template>
<xsl:template mode="recurse" match="~jt:java.io.File[file:isDirectory(.)]">
<xsl:apply-templates mode="#current" select="file:listFiles(.)"/>
</xsl:template>
<xsl:template mode="recurse" match="~jt:java.io.File">
<xsl:apply-templates mode="output" select="xs:anyURI(file:toURI(.))"/>
</xsl:template>
<xsl:template mode="output" match="~xs:anyURI[doc-available(.)]">
<doc href="{.}"/>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment