[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

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)
xsl when 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&apos;'">  

I have also tried to put the character reference on the same line:

   <xsl:when test="substring($Nom,1,2) = 'l&#39;'">  

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 "&#39;">
]>
<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&apos;'">
    <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>.&#xA;</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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.