|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] How to get an apostrophe into a test expression
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








