<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output encoding="utf-8" method="xml" indent="yes"/>
	<!--
	replace href="*.txt" with href="*.html"
	-->
	<xsl:template match="/ | @* | node()">
		<xsl:copy>
			<xsl:apply-templates select="@* | node()"/>
		</xsl:copy>
	</xsl:template>
	<xsl:template match="@href">
		<xsl:variable name="href">
			<xsl:choose>
				<xsl:when test="contains(., '#')">
					<xsl:variable name="path" select="substring-before(., '#')"/>
					<xsl:variable name="anchor" select="substring-after(., '#')"/>
					<xsl:variable name="newpath">
						<xsl:choose>
							<xsl:when test="substring($path, string-length($path) - 3) = '.txt'">
								<xsl:value-of select="concat(substring-before($path, '.txt'), '.html')"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="$path"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:variable>
					<xsl:value-of select="concat($newpath, '#', $anchor)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:choose>
						<xsl:when test="substring(., string-length(.) - 3) = '.txt'">
							<xsl:value-of select="concat(substring-before(., '.txt'), '.html')"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="."/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:attribute name="href"><xsl:value-of select="$href"/></xsl:attribute>
	</xsl:template>
</xsl:stylesheet>
