Recent Saxon releases have a lot of customisation machinery in this area. (Note
that almost everything about the collection() function is going to be
processor-dependent).
By default Saxon guesses the media type from the "file extension" (even though
"file extension" isn't really a defined concept for URIs.). There is then a
mapping from media types to ResourceFactory classes for processing each media
type. Both mappings (from file extension to media type, and from media type to
ResourceFactory) can be set either in the Saxon configuration file or
programmatically in the Configuration object. Here are the default settings:
registerFileExtension("xml", "application/xml");
registerFileExtension("html", "application/html");
registerFileExtension("atom", "application/atom");
registerFileExtension("xsl", "application/xml+xslt");
registerFileExtension("xslt", "application/xml+xslt");
registerFileExtension("xsd", "application/xml+xsd");
registerFileExtension("txt", "text/plain");
registerFileExtension("MF", "text/plain");
registerFileExtension("class", "application/java");
registerFileExtension("json", "application/json");
registerFileExtension("", "application/binary");
registerMediaType("application/xml", XmlResource.FACTORY);
registerMediaType("text/xml", XmlResource.FACTORY);
registerMediaType("application/html", XmlResource.FACTORY);
registerMediaType("text/html", XmlResource.FACTORY);
registerMediaType("application/atom", XmlResource.FACTORY);
registerMediaType("application/xml+xslt", XmlResource.FACTORY);
registerMediaType("application/xml+xsd", XmlResource.FACTORY);
registerMediaType("application/rdf+xml", XmlResource.FACTORY);
registerMediaType("text/plain", UnparsedTextResource.FACTORY);
registerMediaType("application/java", BinaryResource.FACTORY);
registerMediaType("application/binary", BinaryResource.FACTORY);
registerMediaType("application/json", JSONResource.FACTORY);
The four standard ResourceFactory implementations are for XML, JSON, text, and
binary, but you can add your own.
Alternatively, as Martin suggests, you can use uri-collection() to get the list
of URIs, and then decide in your XSLT code how to process each one.
Michael Kay
Saxonica
On 8 May 2019, at 07:50, Martin Honnen martin(_dot_)honnen(_at_)gmx(_dot_)de
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
Am 08.05.2019 um 04:40 schrieb dvint(_at_)dvint(_dot_)com
<mailto:dvint(_at_)dvint(_dot_)com>:
I'm trying to use a collection() to process all files in a directory. The
directory may have text, pddf, images files in addition to my DITA file.
I've created this little test
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<http://www.w3.org/1999/XSL/Transform>
xmlns:xs="http://www.w3.org/2001/XMLSchema"
<http://www.w3.org/2001/XMLSchema>
exclude-result-prefixes="xs"
version="2.0">
<xsl:variable name="fileSet"
select="collection('/Users/danvint/pubsrc-other/formatting-sample?select=*.*;recurse=yes')"/>
<xsl:template match="/">
<xsl:apply-templates select="$fileSet" mode="collectionprocessing"/>
</xsl:template>
<xsl:template match="/" mode="collectionprocessing">
'<xsl:value-of select="document-uri()"/>' <xsl:value-of
select="doc-available(document-uri())"/>
</xsl:template>
</xsl:stylesheet>
Note that in XSLT/XPath 3 there is also a uri-collection function you can use
to simply get a sequence/collection of URIs instead of having to load the
complete files: https://www.w3.org/TR/xpath-functions/#func-uri-collection
<https://www.w3.org/TR/xpath-functions/#func-uri-collection>
Arguments for Saxon should be the same as for collection.
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by
email <>)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--