daz_oldham wrote:
Each hotel has the attribute @StarRating which is one of the following
values:
*
**
***
****
*****
Is it possible to pass my attribute to a custom function that could
then do in effect a case statement on them, replacing it with an image
to represent the star rating?
Are you using XSLT 1.0 or 2.0?
Only XSLT 2.0 allows you to write custom functions with XSLT itself.
With XSLT 1.0 you need to write a named template e.g.
<xsl:template name="get-image">
<xsl:param name="stars" />
<xsl:variable name="starCount" select="string-length($stars)" />
<img alt="{$starCount} stars"
src="starsImage{$starCount}.gif" />
</xsl:template>
You can then call that template with e.g.
<xsl:call-template name="get-image">
<xsl:with-param name="stars" select="@StarRating" />
</xsl:call-template>
That is simply an example assuming that an HTML
<img alt="4 stars" src="starsImage4.gif">
should be generated for the attribute value '****'.
--
Martin Honnen
http://JavaScript.FAQTs.com/