Reputation: 55615
I have an XSLT script that I use for code generation where I process multiple input XML files, and output the files to Javascript code. For each xml input file, I output one Javascript file.
So, I would have the following files/transformations occuring:
view1.xml -> view1.js
view2.xml -> view2.js
...
Now I have a requirement to also create a one additional file during the XSL processing where I will need to append information regarding each input file processed to a common Javascript file.
So, now I would have:
view1.xml -> view1.js / append to common.js
view2.xml -> view2.js / append to common.js
...
My question is, is it possible to append to a file during the processing of multiple input files? I am currently using Saxon 9.1.0.7, and I looked at the xsl:result-document element, but this appears to overwrite any previously written content.
Thanks.
Upvotes: 0
Views: 4889
Reputation: 338326
No, I don't think you can append to an existing (non-XML, even) file from within XSLT.
On the other hand, appending a result to a file is easily done in the environment that runs your transformation. Be it a programming language or a shell, text file concatenation should be a trivial excercise. I suggest you do it there, instead of trying to find some way of bending XSLT to do it.
Upvotes: 2
Reputation: 706
There is a function in XSLT "document()". You can use this to process multiple xml input files from a single XSLT and hence a single output, I am not sure if it helps in your case.
some thing like.
<xsl:apply-templates select="document('doc1.xml')"/>
<xsl:apply-templates select="document('doc2.xml')"/>
<xsl:apply-templates select="document('doc3.xml')"/>
<xsl:template match='nodeX">do something</xsl:template>
<xsl:template match='nodeY">do something else</xsl:template>
Upvotes: 1