XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 13th, 2004, 09:01 AM
fatmonk fatmonk is offline
The Monk that is Fat.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: UK
Posts: 72 fatmonk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 14 m 24 sec
Reputation Power: 5
Question Search and replace

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">
<xslaram name="str" />
<xslaram name="find" />
<xslaram 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>
<xsltherwise>
<xsl:value-of select="$str" />
</xsltherwise>
</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.

Reply With Quote
  #2  
Old April 13th, 2004, 09:38 AM
khwang's Avatar
khwang khwang is offline
Über nübe
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Babylon 4
Posts: 240 khwang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 27 sec
Reputation Power: 5
would this help?

<xsl:value-of select="whatever" disable-output-escaping='yes' />
__________________
Hello, old friend...

Reply With Quote
  #3  
Old April 13th, 2004, 11:03 AM
fatmonk fatmonk is offline
The Monk that is Fat.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: UK
Posts: 72 fatmonk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 14 m 24 sec
Reputation Power: 5
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

Reply With Quote
  #4  
Old April 14th, 2004, 12:21 AM
fpmurphy fpmurphy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: USA
Posts: 262 fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 23 h 28 m 59 sec
Reputation Power: 6
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

Reply With Quote
  #5  
Old April 14th, 2004, 03:55 AM
fatmonk fatmonk is offline
The Monk that is Fat.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: UK
Posts: 72 fatmonk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 14 m 24 sec
Reputation Power: 5
Talking

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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Search and replace


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway