|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Pretty new to XSLT, so this should be an easy one for you lot.
Background: I'm trying to get a system working with Amazon's AWS. It's all working pretty well (enough to have gone live with anyway), but I still have one little problem. I have a widget that lists four albums by a particular artist from an artist search. The artist name that is returned by AWS is then used to build a new URL to create a link at the bottom of the widget to see more items from that artist. (You can see all of this at www.gigpics.co.uk when you view either a picture by an artist or the thumbnails for an artist). The problem is that some of the artist names returned contain ampersands (eg Adam & the Ants). Obviously this will screw up my URL as my Artist parameter gets truncated after 'Adam'. Anyway, the solution I've come up with is to translate the ampersand in the artist name to %26 ( I think thats the right code ), but the normal xsl string replace function will only swap single characters as I understand. But then I found the following lovely looking script: <xsl:comment> template replace(str,find,rep) </xsl:comment> <xsl:template name="replace"> <xsl aram name="str" /><xsl aram name="find" /><xsl aram name="rep" /><xsl:choose> <xsl:when test="contains($str,$find)"> <xsl:value-of select="substring-before($str,$find)" /> <xsl:value-of select="$rep" /> <xsl:call-template name="replace"> <xsl:with-param name="str" select="substring-after($str,$find)" /> <xsl:with-param name="find" select="$find" /> <xsl:with-param name="rep" select="$rep" /> </xsl:call-template> </xsl:when> <xsl therwise><xsl:value-of select="$str" /> </xsl therwise></xsl:choose> </xsl:template> My problem is I don't know how to cal this from within my own .xsl file. If anyone can give me pointers I'd really appreciate it. Thanks, Dan [Edit: He he he, just noticed that the xsl code had the smilies translated. I would switch them of, but I think it makes xsl far more enjoyable!] Last edited by fatmonk : April 13th, 2004 at 09:04 AM. |
|
#2
|
||||
|
||||
|
would this help?
<xsl:value-of select="whatever" disable-output-escaping='yes' />
__________________
Hello, old friend... |
|
#3
|
|||
|
|||
|
Unfortunately not.
As I understand that would result in the ampersand being returned as & (which is how its being returned anyway). And with output escaping not disabled the code for an ampersand is & which also includes an ampersand anyway whoch would still confuse my URL... -Dan |
|
#4
|
|||
|
|||
|
You need to use the xsl:call-template construct i.e.
Code:
<xsl:call-template name="replace">
<xsl:with-param name="str" />
<xsl:with-param name="find" />
<xsl:with-param name="rep" />
</xsl:call-template>
Here is a pointer to further information: http://www.devguru.com/Technologies...lltemplate.html |
|
#5
|
|||
|
|||
|
Excellent.
Thanks for that. I actually found something that worked late last night and got it working. I'd been searching for <xsl:apply-template or some variation of that but then chanced upon <xsl:call-template just as I was about to give up. Cobbled it together and made it work just before I fell asleep. But that link actually explains why I got it to work, so I feel I understand it a bit better now aswell. Cheers, Dan |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Search and replace |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|