Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Replace attribute value

From: Martin Honnen <mahotrash@-----.-->
To: 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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent