W3C home > Mailing lists > Public > xsl-editors@w3.org > October to December 2007

Replace case insensitive

From: axdmoraes <alexmoraes@gmail.com>
Date: Mon, 15 Oct 2007 11:47:47 -0700 (PDT)
Message-ID: <13219155.post@talk.nabble.com>
To: xsl-editors@w3.org


Hi,

     I need to find some word in the xml and put a tag <high> around it. I
did it using the Dave Pawson´s search and replace acronym´s
method.(http://www.dpawson.co.uk/xsl/sect2/replace.html#d9478e115)
Now i need that this works in case-insensitive.  Can anyone help me?


Here is my code...

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" omit-xml-declaration="yes"/>
	<xsl:param name="palavra"/>

	<xsl:template match="/">
		<xsl:apply-templates/>
	</xsl:template>
	<xsl:template match="@*|*">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
	</xsl:template>
	<xsl:template match="text()">
		<xsl:call-template name="globalreplace">
			<xsl:with-param name="toreplace" select="$palavra"/>
			<xsl:with-param name="output" select="."/>
		</xsl:call-template>
	</xsl:template>
	
	<xsl:template name="globalreplace">
	<xsl:param name="toreplace"/>
	<xsl:param name="output"/>
	<xsl:variable name="outputlower">
		<xsl:value-of
select="translate($output,'ABCDEFGHIJKLMNOPQRSTUVXYZ','abcdefghijklmnopqrstuvxyz')"/>
	</xsl:variable>
		<xsl:choose>
			<xsl:when test="not(string($toreplace))">
				<xsl:value-of select="$output"/>
			</xsl:when>
			<xsl:when test="not(string($output))"/>
			<xsl:otherwise>
				<xsl:variable name="singlereplace">
				<xsl:choose>
					<xsl:when test="string-length(substring-before($toreplace,'|'))>0">
						<xsl:value-of select="substring-before($toreplace,'|')"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="$toreplace"/>
					</xsl:otherwise>
				</xsl:choose>
				</xsl:variable>
				<xsl:choose>
					<xsl:when test="contains($outputlower, $singlereplace)">
						<xsl:variable name="before">
							<xsl:value-of select="translate(substring-before($outputlower,
$singlereplace),$outputlower,$output)"/>
							<!--xsl:value-of
select="substring-before($output,$singlereplace)"/-->
						</xsl:variable> 
						<xsl:variable name="after">
							<xsl:value-of select="translate(substring-after($outputlower,
$singlereplace),$outputlower,$output)"/>
							<!--xsl:value-of select="substring-after($output,$singlereplace)"/-->
						</xsl:variable>
						<xsl:call-template name="globalreplace">
							<xsl:with-param name="output" select="$before"/>
							<xsl:with-param name="toreplace"
select="substring-after($toreplace,'|')"/>
						</xsl:call-template>
						<high><xsl:value-of select="$singlereplace"/></high>
						<xsl:call-template name="globalreplace">
							<xsl:with-param name="output" select="$after"/>
							<xsl:with-param name="toreplace"
select="substring-after($toreplace,'|')"/>
						</xsl:call-template>
					</xsl:when>
					<xsl:otherwise>
						<xsl:call-template name="globalreplace">
							<xsl:with-param name="output" select="$output"/>
							<xsl:with-param name="toreplace"
select="substring-after($toreplace,'|')"/>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	</xsl:stylesheet>


thanks,

Alexandre
-- 
View this message in context: http://www.nabble.com/Replace-case-insensitive-tf4629525.html#a13219155
Sent from the w3.org - xsl-editors mailing list archive at Nabble.com.
Received on Monday, 15 October 2007 18:47:55 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 7 December 2009 10:59:58 GMT