<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:r="http://nwalsh.com/xmlns/extreme2006/recipes/"
		xmlns:saxon="http://saxon.sf.net/"
		version="2.0">

  <xsl:output method="text"/>

  <xsl:param name="sample-doc">
    <doc>
      <releaseinfo role="cvs">$Id: matches.xsl,v 1.3 2006-08-10 21:12:03 ndw Exp $</releaseinfo>
    </doc>
  </xsl:param>

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

  <xsl:template match="releaseinfo">
    <xsl:text>Original value:&#10;</xsl:text>
    <xsl:value-of select="."/>
    <xsl:text>&#10;&#10;Match/Replace value:&#10;</xsl:text>
    <xsl:choose>
      <xsl:when test="matches(., '[1-9][0-9]{3}-[0-1][0-9]-[0-3][0-9]')">
	<xsl:value-of select="replace(., '([1-9][0-9]{3})-([0-1][0-9])-([0-3][0-9])',
		                      '$2/$3/$1')"/>
      </xsl:when>
      <xsl:otherwise>
	<xsl:value-of select="."/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>
