Stylesheet example

For those keen to get started with XSLT, the following stylesheet is a simple but working example that can be modified and extended to test the concepts described in the following chapters:

<xsl:stylesheet
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns="http://www.w3.org/TR/xhtml1/strict">

  <xsl:template match="book">
    <HTML><BODY><xsl:apply-templates/></BODY></HTML>
  </xsl:template>

  <xsl:template match="title">
    <H1><xsl:apply-templates/></H1>
  </xsl:template>

  <xsl:template match="author">
    <H3><xsl:apply-templates/></H3>
  </xsl:template>

  <xsl:template match="publisher">
    <P><I><xsl:apply-templates/></I></P>
  </xsl:template>

</xsl:stylesheet>

This stylesheet can be used to process XML source documents such as the following: ...

Get XSL companion, The 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.