Hello,
I am struggling with the following issue, which is that I need to be able to output XML files to multiple folders based on the XML filename using XSLT.
All files with names starting with B should go to one folder, files starting C go to another folder and so on..
I have the following XSLT and it works fine to generate the needed files, but I am not able to output to multiple folders, which is what I need.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/">
<xsl:output method="xml" doctype-public="-//OASIS//DTD DITA Glossary//EN"
doctype-system="glossary.dtd" omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="title"/>
<xsl:param name="files"
select="collection('../../../DITA/?select=%5BA-Z%2D%27%20%28%29%2C%5D%7B2,%7D.dita;recurse=yes')"/>
<xsl:template match="node()">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:for-each select="$files//topic">
<xsl:value-of select="text()" disable-output-escaping="yes"/>
<xsl:result-document href="DITA/glossentries_all/{title/text()|title/b/text()}.dita">
<glossentry id="{concat('dita', generate-id())}">
<glossterm id="{concat('my_title', generate-id())}">
<xsl:value-of select="title"/>
</glossterm>
<glossdef>
<xsl:for-each select="body">
<xsl:apply-templates/>
</xsl:for-each>
<shortdesc/>
</glossdef>
</glossentry>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Here is the resulting DITA XML file.
Code:
<!DOCTYPE glossentry
PUBLIC "-//OASIS//DTD DITA Glossary//EN" "glossary.dtd">
<glossentry xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/"
id="testd30e1">
<glossterm id="dita_titled30e1">Glossary entry test</glossterm>
<glossdef>
<p>DITA XML content text.</p>
<shortdesc/>
</glossdef>
</glossentry>
I am using Saxon-EE 9.5.02. The desired filename is derived from the title of the DITA file, so with the above sample the title is Glossary entry test.dita and that part is working fine.