Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 8th, 2006, 07:49 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default NUMBER OR STRING

Hi,

NOTE: Using MSXML 4 XSLT 1

In the xslt below I need to know whether to add String or Number to the attribute ss:type. i.e

<Data ss:Type="String"> or <Data ss:Type="Number">

Sometimes my xml will contain numbers like 2003 and 2004.

<ColGrp heading="Year">
 <Col heading="2003"/>
 <Col heading="2004"/>
</ColGrp>

or they will contain strings Test A .....

<ColGrp heading="About">
        <Col heading="Test A" />
        <Col heading="Test B" />
        <Col heading="Test C" />
</ColGrp>

In XSLT there isn't a function like isNumber or is String. So how can I achieve that ?

I need to do something like this:
<xsl:if test="@heading is a number ">
<Data ss:Type="Number">
   <xsl:value-of select="@heading"/>
 </Data>
</xsl:if>

XSLT

<Row>
<xsl:for-each select="ancestor::Columns//Col">
<xsl:if test="position()=1">
  <Cell ss:MergeDown="{$colgrps}"/>
</xsl:if>
<Cell ss:MergeAcross="{$countRowSpan}" ss:StyleID="s24">
 <Data ss:Type="String">
   <xsl:value-of select="@heading"/>
 </Data>
</Cell>
</xsl:for-each>
</Row>
 
Old September 8th, 2006, 07:57 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The curious expression

number($x) = number($x)

returns true if $x can be converted to a number, and false if it can't.

Or you can write

string(number($x)) = 'NaN'

if that seems less bizarre.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 8th, 2006, 08:10 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Many thanks Michael.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to count the number of occurence of a string ? khb3283 C# 12 October 5th, 2008 11:10 PM
format-number on a string? dep XSLT 1 October 31st, 2006 01:24 PM
how to replace a string with another string/number crmpicco Javascript How-To 4 March 14th, 2005 12:59 PM
Number String Question CNewbie C++ Programming 28 April 1st, 2004 07:59 PM
Converting a string to a number steve456 Javascript How-To 2 November 17th, 2003 06:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.