|
Subject: How to get an apostrophe into a test expression From: Michel Goossens <Michel.Goossens@xxxxxxx> Date: Tue, 12 Oct 1999 17:39:43 +0100 (MET) |
Suppose I have the following XML file a.xml
<doc>
<a>le ciel</a>
<a>la maison</a>
<a>l'algue</a>
<a>l'est</a>
<a>les enfants</a>
<a>Norma</a>
</doc>
I want to transform this into the partitif article according to
French grammar: de le --> du, de la --> de la , de l' --> de l'
de les --> des; nothing --> de.
So I want to test on the presence of the string "le ", "la ",
"l'", "les" and the rest to decide what to write. I use therefor the
following xsl stylesheet. However, I cannot find a way to "escape" or
"hide" the literal apostrophe on line 24.
<xsl:when test="substring($Nom,1,2) = 'l''">
I have also tried to put the character reference on the same line:
<xsl:when test="substring($Nom,1,2) = 'l''">
but xt recognizes this character as a ', so the following character
gives problems.
a.xsl:24: missing quote
I also tried 'l''' (as works in some languages), but the I get
a.xsl:24: unexpected token
How can I refer to a quote inside a quoted string inside another quoted
string?
The complete xsl file follows.
<?xml version='1.0' encoding="ISO-8859-1"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY apos "'">
]>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="ISO-8859-1"/>
<xsl:template match="//a">
<xsl:variable name="Nom" select="string(.)"/>
<xsl:choose>
<xsl:when test="substring($Nom,1,3) = 'le '">
<xsl:text>du </xsl:text>
<xsl:value-of select="substring-after($Nom,' ')"/>
</xsl:when>
<xsl:when test="substring($Nom,1,3) = 'la '">
<xsl:text>de </xsl:text>
<xsl:value-of select="$Nom"/>
</xsl:when>
<xsl:when test="substring($Nom,1,3) = 'les'">
<xsl:text>des </xsl:text>
<xsl:value-of select="$Nom"/>
</xsl:when>
<xsl:when test="substring($Nom,1,2) = 'l''">
<xsl:text> de </xsl:text>
<xsl:value-of select="$Nom"/>
</xsl:when>
<xsl:otherwise>
<xsl:text> est la capitale de </xsl:text>
<xsl:value-of select="$Nom"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>.
</xsl:text><!-- retour à la ligne -->
</xsl:template>
</xsl:stylesheet>
Thanks for helping me solve this problem. mg
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| A FAQ question about non-Latin char, Jarno Elovirta | Thread | Re: How to get an apostrophe into a, Eric van der Vlist |
| Re: Multiple Output Documents with , Clark C. Evans | Date | Re: Multiple Output Documents with , Kirk V. Hastings |
| Month |