|
|
Rank: Devotee
Joined: 4/12/2007 Posts: 93 Location: Amsterdam
|
Hi all! I have this bit of code to replace certain words in a string. Code:<xsl:value-of select="umbraco.library:Replace($KeywordsRAW,'passeert','')"/> The problem I have that this I don't know how I should check on MULTIPLE (different) words in for example my bodytext. This anybody knows how to do this?? thanks in advance, Chris
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 790 Location: Århus, Denmark
|
I guess you could do it like this: Code:<xsl:value-of select="umbraco.library:Replace(umbraco.library:Replace($KeywordsRAW,'MyFirstWord',''),'MySecondWord','')"/> It's pretty repetitive and not very pretty... How many different words are we talking here? You could probably take advantage of XSLT's template syntax to do this as well...
|
|
 Rank: Addict
Joined: 7/19/2006 Posts: 790 Location: Århus, Denmark
|
I just played around with it a bit, and came up with this example. It does concatenation instead of replace action, but it proves the point. The xml that it uses it this: <root> <value>test1</value> <value>test2</value> <value>test3</value> </root> Code: <xsl:template match="/"> <xsl:variable name="allnodes" select="root" /> <xsl:call-template name="myloop"> <xsl:with-param name="test" select="$allnodes/value" /> </xsl:call-template> </xsl:template>
<xsl:template name="myloop"> <xsl:param name="test" /> <xsl:param name="mystring" /> <xsl:variable name="remnodes" select="$test[position() > 1]" /> <xsl:choose> <xsl:when test="count($test) > 1"> <xsl:variable name="newstring" select="concat($mystring,concat($test[position() = 1],','))" /> <xsl:call-template name="myloop"> <xsl:with-param name="test" select="$remnodes" /> <xsl:with-param name="mystring" select="$newstring" /> </xsl:call-template> </xsl:when> <xsl:when test="count($test) = 1"> <xsl:variable name="newstring" select="concat($mystring,$test[position() = 1])" /> <xsl:call-template name="myloop"> <xsl:with-param name="test" select="$remnodes" /> <xsl:with-param name="mystring" select="$newstring" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$mystring"/> </xsl:otherwise> </xsl:choose> </xsl:template>
Can you follow what is happening here?
|
|
 Rank: Umbracoholic
Joined: 9/8/2006 Posts: 1,698 Location: KY, USA
|
This might be a good use of a small C# function right in the xslt file. Maybe using regex? cheers, doug.
MVP 2007-2009 - Official Umbraco Trainer for North America - Percipient Studios
|
|
Rank: Devotee
Joined: 4/12/2007 Posts: 93 Location: Amsterdam
|
Thanks for holding my hand! I've got it working! greetings, Chris
|
|
|
Guest |