Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Replace attribute value >Thread Next - Re: Replace attribute value Re: Replace attribute valueTo: NULL Date: 2/8/2008 4:55:00 PM Olivier MATROT wrote: > One last question : Could we use a function to translate ? This will > eliminate the need to copy strings for each attribute I would like to > process. I am not sure I understand what you are looking for. Standard XSLT 1.0 does not allow you to define your own functions. All you can do is write named templates and call them with xsl:call-template. With XSLT 2.0 you have much more power, first it allows you to use variables in match patterns (meaning my first suggestion would work), secondly it has functions 'upper-case' and 'lower-case' so you don't need the cumbersome 'translate' function, and furthermore you can define your own functions in stylesheets. Microsoft does not have an XSLT 2.0 processor but there are other implementations around, one being Saxon (currently version 9) from <URL:http://saxon.sourceforge.net/> which has both a Java and a .NET version. With XSLT 1.0 instead of doing e.g. <xsl:template match="User/@advancedViewing[translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'vrai']"> <xsl:attribute name="{name()}"> <xsl:text>true</xsl:text> </xsl:attribute> </xsl:template> <xsl:template match="User/@advancedViewing[translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'faux']"> <xsl:attribute name="{name()}"> <xsl:text>false</xsl:text> </xsl:attribute> </xsl:template> you might prefer one template <xsl:param name="ul" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/> <xsl:param name="ll" select="'abcdefghijklmnopqrstuvwxyz'"/> <xsl:template match="User/@advancedViewing"> <xsl:variable name="lvalue" select="translate(., $ul, $ll)"/> <xsl:attribute name="{name()}"> <xsl:choose> <xsl:when test="$lvalue = 'vraix'"> <xsl:text>true</xsl:text> </xsl:when> <xsl:when test="$lvalue = 'faux'"> <xsl:text>false</xsl:text> </xsl:when> </xsl:choose> </xsl:attribute> </xsl:template> -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
