replacing string
I have a xml file like this.
<projectteam>
<projectname>The Killer Application {a href="http://www.hotmail.com"}hotmail.com{/a}</projectname>
</projectteam>
but i want to convert '}' to '>' and '{' to '<' with xsl this function.
<xsl:template name="string-replace" >
<xsl:param name="string"/>
<xsl:param name="from"/>
<xsl:param name="to"/>
<xsl:choose>
<xsl:when test="contains($string,$from)">
<xsl:value-of select="substring-before($string,$from)"/>
<xsl:value-of select="$to"/>
<xsl:call-template name="string-replace">
<xsl:with-param name="string" select="substring-after($string,$from)"/>
<xsl:with-param name="from" select="$from"/>
<xsl:with-param name="to" select="$to"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string" disable-output-escaping="yes"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
cuz i might have to generate html and other format. but when i try like this, it converts only '>' to a> which is html tag. but i want '<'. is there any way to do this? please help...
[1426 byte] By [
caesarkim] at [2007-11-18 16:20:01]

# 1 Re: replacing string
You can never output a lone < or > character in an xml file. You could set the output content type to text, in which case you should get the result you want. But this is a bad idear if you are using the stylesheet in an application that expects xml/html output.
But you are really, looking at this the wrong way, trying to produce html elements by outputting their string encoding. Thats not the way to go.
What you should do is create the anchor using an xsl:element, something like this.
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:text>www.w3c.org</xsl:text>
</xsl:attribute>
<xsl:text>w3c</xsl:text>
</xsl:element>
khp at 2007-11-10 3:28:22 >

# 3 Re: replacing string
Originally posted by caesarkim
I understand that you are saying. but i have to generate it for html and other format(XSL-FO)that generates PDF.
That makes no difference.
Originally posted by caesarkim
The problem is that i don't know where the anchor tag is going to be embedded in xml. it comes from a database table.
If you know where to put the < character you must also know where to put the element.
Originally posted by caesarkim
that's why i want to replace '{' with '<' something like this.
You are still looking at it the wrong way.
Originally posted by caesarkim
is there another solution?
No.
khp at 2007-11-10 3:30:30 >
