Tranform XML using XSLT (XML XSLT)

To transform XML to another XML/HTML/TEXT format using XSLT., we need the following files.

  • Input XML (.xml)
  • XSLT file which contains the transformation script. (.xsl)

The below XML (input.xml) input file, can be transformed into a html with the xsl (trans.xsl) file.

Sample Input XML:
File: input.xml

In the above XML file, we could see xml-stylesheet tag which defines the transformation xsl file., which when opened by Chrome/Firefox browser,

The transformation will be applied and output will be displayed in the browsers.

Tranformation XSL:
File: trans.xsl

  • The xsl:stylesheet with xmlns:xsl attribute defines the file is a XSL tranformation content.,
  • The <xsl:value-of> tag defines the value present in the source xml content values.
  • The “select” attribute defines the corresponding XPATH in the source xml(input.xml)
    • e.g., Person/Name defines the value of input XML tag elements value “Sherlock” ( Traverse through the XPATH Sherlock )

Finally, Once done, when Opening the input.XML file in the browser, the corresponding transformation is applied and the output will be like below.

Details
Name Sherlock
Profession Detective
Country England

The output source code after the transformation is below.

Leave a Reply

Your email address will not be published. Required fields are marked *