On Tue, 2004-10-12 at 11:02, TOURNIER E InfoMcpAta wrote:
> Bonjour,
>
> Ca y est !! Apres une matinéee de recherche sur Google, j'ai pu me rapprocher d'un cas ( http://www.developpez.net/forums/viewtopic.php?t=110733 <http://www.developpez.net/forums/viewtopic.php?t=110733&highlight> &highlight=)
> Il s'agit visiblement d'un probleme d'interpretation de la chaine mod par le processeur :
>
> PAS BIEN : <xsl:when test="(position() mod2) !=0">
Pour lui, "mod2" est un "token" qui est incorrect.
> BIEN : <xsl:when test="(position() mod 2) !=0">
> ================================^
Ou encore <xsl:when test="position() mod 2 != 0"> qui, je le maintiens,
fait exactement ce que vous souhaitez.
Pour vous en convaincre, essayez de transformer
<foo>
<bar>1</bar>
<bar>2</bar>
<bar>3</bar>
</foo>
par
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="foo">
<foo>
<xsl:apply-templates select="*"/>
</foo>
</xsl:template>
<xsl:template match="bar">
<bar>
<xsl:choose>
<xsl:when test="position() mod 2 != 0">
<when>
<xsl:value-of select="position()"/>
</when>
</xsl:when>
<xsl:otherwise>
<otherwise>
<xsl:value-of select="position()"/>
</otherwise>
</xsl:otherwise>
</xsl:choose>
</bar>
</xsl:template>
</xsl:transform>
ou (mieux) par :
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="foo">
<foo>
<xsl:apply-templates select="*"/>
</foo>
</xsl:template>
<xsl:template match="bar">
<otherwise>
<xsl:value-of select="position()"/>
</otherwise>
</xsl:template>
<xsl:template match="bar[position() mod 2 != 0]">
<when>
<xsl:value-of select="position()"/>
</when>
</xsl:template>
</xsl:transform>
> MIEUX(?) : <xsl:variable name="pos" select="position()"/>
> <xsl:variable name="posMod" select="$pos mod 2"/>
> <xsl:choose>
> <xsl:when test="$posMod != 0">
Pourquoi faire compliqué quand on peut faire simple?
Cordialement,
Eric van der Vlist
--
Have you ever thought about unit testing XSLT templates?
http://xsltunit.org
------------------------------------------------------------------------
Eric van der Vlist http://xmlfr.org http://dyomedea.com
(ISO) RELAX NG ISBN:0-596-00421-4 http://oreilly.com/catalog/relax
(W3C) XML Schema ISBN:0-596-00252-1 http://oreilly.com/catalog/xmlschema
------------------------------------------------------------------------
--
Devenez redacteur <XML>fr et contribuez au developpement du
xml francophone (http://xmlfr.org/infos/redacteurs/) !
Liste de diffusion "xml-tech@xmlfr.org" (http://xmlfr.org).
Cette liste est a votre disposition pour discuter en francais de
tout sujet technique lie a XML.
Pour resilier votre abonnement, envoyez un message contenant
la commande "unsubscribe" a xml-tech-request@xmlfr.org
(mailto:xml-tech-request@xmlfr.org?Subject=unsubscribe)
Received on Tue Oct 12 11:50:52 2004