A Simple Example: Hello World

I think the best way to teach a programming language is to start with a very simple, contrived example. So, here is an XSLT version of Hello World.

Stylesheet (HelloWorld.xsl)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <HelloWorld>Howdy!</HelloWorld>
  </xsl:template>
</xsl:stylesheet>

Here is our source document.

Source (Goodbye.xml)
<?xml version="1.0" encoding="UTF-8"?>
<Goodbye>
  you all
</Goodbye>

We can run the source document through an XSLT processor using our HelloWorld.xsl stylesheet and produce the following result.

Result (HelloWorld.xml)
 <?xml version="1.0" encoding="UTF-8"?> <HelloWorld> Howdy! </HelloWorld> ...

Get Using XML with Legacy Business Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.