I have multiple XML files.all nodes are similar. Please provide an example how to merge XML files using STAX Parser and apply a stylesheet on it.
-
How is this question related to another question of yours?Mathias Müller– Mathias Müller2014-10-27 13:19:30 +00:00Commented Oct 27, 2014 at 13:19
-
i tried to achieve this requirement by style sheet.but later decided to use STAX parser because every time file names will change.user2779221– user27792212014-10-30 00:33:36 +00:00Commented Oct 30, 2014 at 0:33
Add a comment
|
1 Answer
If you want to apply XSLT to several XML documents then (with pure XSLT, I don't know about Stax) you can simply use the document function (XSLT 1.0 and 2.0) or the collection function (with XSLT 2.0) e.g.
<xsl:template match="/">
<root>
<xsl:apply-templates select="document('file1.xml')/* | document('file2.xml')/* | document('file3.xml')/*"/>
</root>
</xsl:template>
then add templates matching the element names in the documents you want process.
4 Comments
user2779221
This works for fixed file names. but my use case is different, files names will change based on the job we are going to run.
Martin Honnen
If you use an XSLT 2.0 processor like Saxon 9 then you should be able to use the
collection function to load files from a directory or folder. Let us know whether that is an option for you.user2779221
Thanks. It works for me .Please gimme complete example ,if possible.
rmarq423
I'm performing a very similar action from what it sounds like the asker is doing... Curious as to how to approach this.