Software Development

Modify XML Element Content in Java using XSLT

This post demonstrates how to modify some parts of the XML content in Java using XSLT. The example herein is rather straight-forward but provides basic working codes before moving to more advanced stuff.



Stuff used.

  • Java 8 (JDK)
  • IntelliJ IDEA – optional
  • Spring Boot – optional
  • Windows 10 – optional
  • XSLT 1.0


Modify some element text in input.xml using Java based on rules and expressions declared in translation.xsl. The modified XML content is written to output.xml.

We are to prefix the heading value with CONFIDENTIAL: and append Please do not print! to the body value.


Sample XML and XSL Files

These are the XML files to be used here – input.xml and translation.xsl

Translation.xsl contains rules and expressions on how to go about replacing stuff in the input.xml and produce the output.xml file with some Java codes.


Target Output XML

The output.xml will have this content:

Java Codes



Download the Codes


Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.

You Might Also Like