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.

2
  • How is this question related to another question of yours? Commented 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. Commented Oct 30, 2014 at 0:33

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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.
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.
Thanks. It works for me .Please gimme complete example ,if possible.
I'm performing a very similar action from what it sounds like the asker is doing... Curious as to how to approach this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.