I have two variables which contain comma separated values:-
<xsl:variable name="Include-Cities" select="'London, Paris, Washington, Tokyo'"/> <xsl:variable name="Exclude-Cities" select="'Paris, Tokyo'"/> I have a requirement to remove the values in $Include-Cities which match those found in $Exclude-Cities, so in a way I am subtracting those values from the $Include-Cities variable and outputting the result.
I have looked around the web and found the following example which provides search and replace functionality and which works if the order of the cities in $Exclude-Cities matches the order in $Include-Cities, but fails if the order of values if different.
I am stuck as the values in both lists can change daily and i will never know what those values are, therefore i don't think performing a sort (if its possible) will work.
The example i found:-
<xsl:template name="replace-string"> <xsl:param name="text"/> <xsl:param name="replace"/> <xsl:param name="with"/> <xsl:choose> <xsl:when test="contains($text,$replace)"> <xsl:value-of select="substring-before($text,$replace)"/> <xsl:value-of select="$with"/> <xsl:call-template name="replace-string"> <xsl:with-param name="text" select="substring-after($text,$replace)"/> <xsl:with-param name="replace" select="$replace"/> <xsl:with-param name="with" select="$with"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$text"/> </xsl:otherwise> </xsl:choose> </xsl:template> Then i call the template using:-
<xsl:call-template name="replace-string"> <xsl:with-param name="text" select="$Include-Cities"/> <xsl:with-param name="replace" select="$Exclude-Cities" /> <xsl:with-param name="with" select="''"/> </xsl:call-template> I have also looked at examples of tokenizing the values and comparing that way but have had no joy whatsoever.
I know there are string comparsion functions available in 2.0 but I am restricted to using XSLT 1.0.
I am an XSLT noob so can anyone help please?
Any help would be most appreciated
No comments:
Post a Comment