Building-blocks logo. Incremental Development, Inc.

XSL example, XSLT example, XSL sample, XSLT sample, XSL tutorial, XSLT tutorial, stupid XSL trick, stupid XSLT trick.

Charlie's Wing of the Gallery of Stupid XSL and XSLT Tricks

This page is Charlie Halpern-Hamu's wing of the Gallery of Stupid XSL and XSLT Tricks.

Quine

This stylesheet is both a self-reproducing program and a Hello World! program. No matter what the input, the output will be an identical copy of the stylesheet itself. See also:

Input:

<input>Ignore me.</input>

Stylesheet:

<html>Hello World!</html>

Output:

<html>Hello World!</html>

This works by using the Literal Result as Stylesheet feature of XSLT.

Actually, it appears that this stylesheet is in error. The XSLT Recommendation requires that a literal result include the xsl:version attribute. Adding this attribute makes the stylesheet and output no longer identical.

Stylesheet:

<html xsl:version='1.0'
      xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>Hello World!</html>

Output:

<html>Hello World!</html>

Oliver Becker points out that this fails as a Hello World! program as well, in that it adds extra <html> tags to the output. He suggests the following as a proper Hello World! program:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text" />
  <xsl:template match="/">Hello World!</xsl:template>
</xsl:stylesheet>