|
|
|
date: Fri, 8 Feb 2008 12:27:02 +0100,
group: microsoft.public.xsl
back
Re: Replace attribute value
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/
date: Fri, 08 Feb 2008 16:55:06 +0100
author: Martin Honnen
Re: Replace attribute value
My fault, language abuse here.
You sould have read templates.
Thanks for your help that is very valuable.
"Martin Honnen" wrote in message
news:eNrV8rmaIHA.1532@TK2MSFTNGP04.phx.gbl...
> 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/
date: Fri, 8 Feb 2008 17:03:25 +0100
author: Olivier MATROT
|
|