xsl-list
[Top] [All Lists]

RE: [xsl] String ends with ?, ! or not

2008-04-29 18:47:56

XPath 2.0 has an ends-with() function, in XPath 1.0 you can do

substring($in, X) = $test

where X is the string-length of $in minus the string-length of $test.

Michael Kay
http://www.saxonica.com/
 

-----Original Message-----
From: Pankaj Chaturvedi [mailto:pankaj(_dot_)chaturvedi(_at_)idsil(_dot_)com] 
Sent: 29 April 2008 13:04
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] String ends with ?, ! or not

Is there is way, we can test whether a string ENDS-WITH a ?, !.

<articletitle>Dynamics of the trade balance and the terms of 
trade: The J&hyphen;curve&quest;</articletitle>

I am trying to test, whether the <articletitle> string ends 
with &quest; (?) or not. Below is what I've tried to define 
in my stylesheet (note that I've tested Unicode value for 
&quest; as it gives error to define an external entity 
&quest;, which I've done by declaring a ENTITY declaration in XML as
<!ENTITY quest            "[#x0003F]" ><!--=question mark --> ).


<xsl:choose>
      <xsl:when test="./articletitle/contains(string(), '#x0003F')">
               <char><xsl:text> </xsl:text></char>
      </xsl:when>
      <xsl:otherwise>
               <char><xsl:text>, </xsl:text></char>
      </xsl:otherwise>
</xsl:choose>


Question: contains() function just whether string has '?' in 
it or not, which means it will be true for strings like 
"XXXXXXX The J&hyphen;curve&quest; YYYY", whereas I need to 
check whether it ends with or not (Alas I do not know any 
functions apart from starts-with()).


Any suggestions please in this regard.


Pankaj



























Best,

Pankaj Chaturvedi

==============================================================
==============
================



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>