Page 1 of 1

Copy output XML files to multiple folders

Posted: Tue Jun 25, 2013 6:20 pm
by eloralon
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 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: Select all

<?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>

Re: Copy output XML files to multiple folders

Posted: Tue Jun 25, 2013 8:04 pm
by eloralon
I got the files to be copied to multiple folders just as I wanted by using the following line of code, suggested by Michael Kay:

Code: Select all

<xsl:result-document href="DITA/glossentries_all/{substring(title,1,1)}/{title/text()|title/b/text()}.dita"> 
as shown http://p2p.wrox.com/xslt/90410-copy-out ... st292220">