<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:saxon="http://saxon.sf.net/"
                version="2.0">

  <xsl:output method="xhtml"/>

  <xsl:param name="sample-doc">
    <doc>
      <para>This is some 
text where line breaks
don’t matter</para>
<poem>This is
   some text
     where
 they do</poem>
 <para>More paragraph text.</para>
    </doc>
  </xsl:param>

  <xsl:template match="/">
    <xsl:apply-templates select="$sample-doc//doc"/>
  </xsl:template>

  <xsl:template match="doc">
    <html>
      <head>
	<title>Regular Expression Example</title>
	<link href="output.css" type="text/css" rel="stylesheet"/>
      </head>
      <body>
	<h1>Regular Expression Example</h1>
	<xsl:apply-templates/>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="para">
    <p>
      <xsl:apply-templates/>
    </p>
  </xsl:template>

  <xsl:template match="poem">
    <p class="poem">
      <xsl:analyze-string select="." regex="
">
	<xsl:matching-substring><br/></xsl:matching-substring>
	<xsl:non-matching-substring>
	  <xsl:analyze-string select="." regex=" ">
	    <xsl:matching-substring> </xsl:matching-substring>
	    <xsl:non-matching-substring>
	      <xsl:copy-of select="."/>
	    </xsl:non-matching-substring>
	  </xsl:analyze-string>
	</xsl:non-matching-substring>
      </xsl:analyze-string>
    </p>
  </xsl:template>

</xsl:stylesheet>