I want to batch process all the XML files in a directory, generating output filenames based on a value in each XML. I am using the Saxon collection function in conjunction with the base-uri function, but I am having difficulty accessing each URI individually.
Edit: the below stylesheet gives the error message: "A sequence of more than one item is not allowed as the first argument of base-uri()"
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" />
<xsl:param name="input-dir" select="'file:///C:/path/to/directory'"/>
<xsl:template name="main">
<xsl:variable name="input-docs" select="collection(iri-to-uri(concat($input-dir, '?select=*.xml')))"/>
<xsl:variable name="old-filename" select="base-uri($input-docs)"/>
<xsl:variable name="new-filename" select="item[@name = 'LogNo']/text"/>
<xsl:for-each select="$old-filename">
<xsl:result-document href="concat ($new-filename, '.xml')">
<xsl:copy-of select="."/>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Edit: for completeness, I've added the two command line prompts that I've attempted. I'm not sure if the path to the input directory should be specified in the stylesheet or in the command line.
java -jar "C:\path\to\saxon.jar" -it:main -o:"C:\path\to\renamed\XML" -xsl:"C:\path\to\stylesheet.xslt"
java -jar "C:\path\to\saxon.jar" -s:"C:\path\to\input\XML" -o:"C:\path\to\renamed\XML" -xsl:"C:\path\to\stylesheet.xslt"
{}?href="{concat($new-filename, '.xml')}". However, the context of yourfor-eachis going to be a string ($old-filename); maybe you want to select$input-docsinstead?