This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Replacing all Occurences of a String


Hi there
I want to replace the english months with the german months. It is possible
that the elements <sfzRelease/> and <sfzProdjahr/> have several months, like
this:

<sfzRelease>January, February 2001</sfzRelease>

I want at the end:

<sfzRelease>Januar, Februar 2001</sfzRelease>

I took Michael Kay's replace.xsl Stylesheet (Replacing all Occurences of a
String). But I don't want to give it the parameters in the stylesheet
itself. I made a xsl:choose with the parameters, but that isn't accepted.
Can anyone help me with this.
Thanx very much
Roger






<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet
	version="1.O"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


<xsl:param name="replace"/>
<xsl:param name="by"/>

		<xsl:choose>
			<xsl:when test="$replace='January'">
				<xsl:param name="by" select="Januar"/>
			</xsl:when>
		   	<xsl:when test="$replace='February'">
				<xsl:param name="by" select="Februar"/>
			</xsl:when>
			<xsl:when test="$replace='March'">
				<xsl:param name="by" select="März"/>
			</xsl:when>
			<xsl:when test="$replace='May'">
				<xsl:param name="by" select="Mai"/>
			</xsl:when>
			<xsl:when test="$replace='June'">
				<xsl:param name="by" select="Juni"/>
			</xsl:when>
			<xsl:when test="$replace='July'">
				<xsl:param name="by" select="Juli"/>
			</xsl:when>
			<xsl:when test="$replace='October'">
				<xsl:param name="by" select="Oktober"/>
			</xsl:when>
			<xsl:when test="$replace='December'">
				<xsl:param name="by" select="Dezember"/>
			</xsl:when>
		</xsl:choose>


<xsl:template name="do-replace">
	<xsl:param name="text"/>
	<xsl:choose>
	<xsl:when test="contains($text,$replace)">
		<xsl:value-of select="substring-before($text, $replace)"/>
		<xsl:value-of select="$by"/>
		<xsl:call-template name="do-replace">
		<xsl:with-param name="text"
					select="substring-after($text, $replace)"/>
		</xsl:call-template>
	</xsl:when>
	<xsl:otherwise>
		<xsl:value-of select="$text"/>
	</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="sfzRelease | sfzProdjahr">
	<xsl:copy>
	<xsl:copy-of select="@*"/>
	<xsl:apply-templates/>
	</xsl:copy>
</xsl:template>

<xsl:template match="text()">
	<xsl:call-template name="do-replace">
		<xsl:with-param name="text" select="."/>
	</xsl:call-template>
</xsl:template>

</xsl:stylesheet>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]