0

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.

user2779221
  • 135
  • 3
  • 11
  • How is this question related to [another question of yours](http://stackoverflow.com/questions/26512015/merge-two-or-more-xml-files-and-display-as-html-using-xslt)? – Mathias Müller Oct 27 '14 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 Oct 30 '14 at 00:33

1 Answers1

0

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.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • 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. – user2779221 Oct 30 '14 at 00:35
  • 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. – Martin Honnen Oct 30 '14 at 08:28
  • Thanks. It works for me .Please gimme complete example ,if possible. – user2779221 Nov 04 '14 at 01:58
  • I'm performing a very similar action from what it sounds like the asker is doing... Curious as to how to approach this. – rmarq423 Feb 13 '15 at 15:25