You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Biying Huang <bi...@synthematix.com> on 2002/08/08 15:38:14 UTC

how can I detect if a character in a string is a number or not?

Hello, everyone,

In my xml data file, I have an entity like this:
<formula>C12H10N2</fomula>

I need to display this chemical formula in such a way that all the
number characters are smaller and lower than alpha characters.

So in my xslt, how can I detect if a  character in a string is a number
or not?

Thanks in advance for your help.

Biying


Re: how can I detect if a character in a string is a number or not?

Posted by Chuck Paussa <Ch...@systems.dhl.com>.
Create a template that processes substring(formula,1,1) and then calls
itself with substring(formula,2) [That processes the formula one character
at a time
Then do an xsl:choose, xsl:when
test="translate(char,'0123456789','9')='9'">this is a number so fo:inline
subscript

Or something like that. You'll have to look up the proper spelling of those
xsl:functions, and (You really should be asking xsl questions on the xsl
list.

Chuck
----- Original Message -----
From: "Biying Huang" <bi...@synthematix.com>
To: <fo...@xml.apache.org>
Sent: Thursday, August 08, 2002 6:38 AM
Subject: how can I detect if a character in a string is a number or not?


> Hello, everyone,
>
> In my xml data file, I have an entity like this:
> <formula>C12H10N2</fomula>
>
> I need to display this chemical formula in such a way that all the
> number characters are smaller and lower than alpha characters.
>
> So in my xslt, how can I detect if a  character in a string is a number
> or not?
>
> Thanks in advance for your help.
>
> Biying
>
>


Re: how can I detect if a character in a string is a number or not?

Posted by Biying Huang <bi...@synthematix.com>.
I got it with your help. Thank you everyone for your reply. -- Biying

Oleg Tkachenko wrote:

> Biying Huang wrote:
>
> > In my xml data file, I have an entity like this:
> > <formula>C12H10N2</fomula>
> >
> > I need to display this chemical formula in such a way that all the
> > number characters are smaller and lower than alpha characters.
> >
> > So in my xslt, how can I detect if a  character in a string is a number
> > or not?
> There is cool trick about it:
> <xsl:if test="number($char) = number($char)">
>         It's number!
> </xsl:if>
>
> If you want to grasp how it works, recall that NaN is not equal to NaN.
>
> --
> Oleg Tkachenko
> Multiconn International, Israel


Re: how can I detect if a character in a string is a number or not?

Posted by Oleg Tkachenko <ol...@multiconn.com>.
Biying Huang wrote:

> In my xml data file, I have an entity like this:
> <formula>C12H10N2</fomula>
> 
> I need to display this chemical formula in such a way that all the
> number characters are smaller and lower than alpha characters.
> 
> So in my xslt, how can I detect if a  character in a string is a number
> or not?
There is cool trick about it:
<xsl:if test="number($char) = number($char)">
	It's number!
</xsl:if>

If you want to grasp how it works, recall that NaN is not equal to NaN.

-- 
Oleg Tkachenko
Multiconn International, Israel