With most XSLT 2.0 processors you can use the collection
function to access a collection of files from the file system but the concrete syntax depends on the XSLT processor. With Saxon 9 the following works for me:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="chapters" select="collection('.?select=XML*.xml')/chapter"/>
<xsl:template match="toc-item/toc-title">
<xsl:analyze-string select="." regex="chapter\s+([0-9]+)\s+" flags="i">
<xsl:matching-substring>
<xsl:value-of select="."/>
<xsl:value-of select="$chapters[xs:integer(@num) eq xs:integer(regex-group(1))]/chapter-meta/author/name/*"/>
<xsl:text> </xsl:text>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
With your three files XML1.xml
, XML2.xml
, XML3.xml
in the same working directory as the main input the output then is
CHAPTER 1 YEO HWEE YING
CHAPTER 2 TAN CHENG HAN
CHAPTER 3 TAN CHENG HAN
With the version 2013 of AltovaXML the following works for me:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="chapters" select="collection('./XML*.xml')/chapter"/>
<xsl:template match="toc-item/toc-title">
<xsl:analyze-string select="." regex="chapter\s+([0-9]+)\s+" flags="i">
<xsl:matching-substring>
<xsl:value-of select="."/>
<xsl:value-of select="$chapters[xs:integer(@num) eq xs:integer(regex-group(1))]/chapter-meta/author/name/*"/>
<xsl:text> </xsl:text>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
I don't know whether that use of collection
works with the latest version called Raptor of Altova's XSLT engine, I don't have access to that as they don't provide a developer release or license anymore and http://manual.altova.com/RaptorXML/raptorxmlserver/ does not seem to contain a documentation of the use of collection
, at least on quick browsing.