W3C home > Mailing lists > Public > www-xsl-fo@w3.org > October 2004

Evalution Problems

From: Huditsch Roman <Roman.Huditsch@lexisnexis.at>
Date: Wed, 13 Oct 2004 16:27:25 +0200
Message-ID: <AA7BAD89B2B0C746A26452F44939F1E3406FA7@LNGVIEEX1.orac.local>
To: <www-xsl-fo@w3.org>


I run into problems evaluating the end of a string.
Take the following structure for example:

	<token xmlns="">Absicht,</token>
	<token xmlns="">böse</token>
	<token xmlns="">1294ff,</token>
	<token xmlns="">1324f,</token>
	<token xmlns="">1331a</token>
	<token xmlns="">1344</token>
	<token xmlns="">1366</token>

I need to put every string containing numbers into <number> elements.
If there is a number and a comma appears, it should be trimmed.

I wrote a stylesheet for most of the cases, but I think that there must be an easier way to do this task...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:template match="node()| @*">
			<xsl:apply-templates select="@* | node()"/>
	<xsl:template match="keyword">
		<xsl:element name=" keyword ">
			<xsl:apply-templates select="token"/>
	<xsl:template match="token">
			<xsl:when test="contains(., '-')">
						<xsl:when test="contains(.,',')">
							<xsl:value-of select="substring-before(.,',')"/>
							<xsl:value-of select="."/>
			<xsl:when test="contains(., 'ff,')">
						<xsl:when test="string(number(substring-before(., 'ff,')))='NaN'">
								<xsl:value-of select="substring-before(.,',')"/>
								<xsl:value-of select="substring-before(.,',')"/>
			<xsl:when test="contains(., 'f,')">
						<xsl:when test="string(number(substring-before(., 'f,')))='NaN'">
								<xsl:value-of select="substring-before(.,',')"/>
								<xsl:value-of select="substring-before(.,',')"/>

Can you help me?


-----Ursprüngliche Nachricht-----
Von: www-xsl-fo-request@w3.org [mailto:www-xsl-fo-request@w3.org] Im Auftrag von Tim Mooney
Gesendet: Montag, 11. Oktober 2004 23:50
An: www-xsl-fo@w3.org
Betreff: Re: node after current node in xsl:for-each with xsl:sort (was: conditional page-break table based on row number?)

In regard to: Re: node after current node in xsl:for-each with xsl:sort...:

> this list is more for FO issues than XSLT programming (I think) but
> anyway

Sorry about that.  You're right, my question (now) is really about XSLT and
is independent of FO.

>                 <xsl:apply-templates
>                             select="self::*[position() + 1]"
> self::* selects at most 1 node, which will always have position()=1
> but in any case, if you use [] with a numeric value rather than a
> predicate it is short for
> [position()=...]
> so *[1] means *[position()=1]
> and selects the first thing and
> [position() + 1] is short for [position()=(position() + 1)] and selects
> all those elements for which 0=1 ie, it selects the empty set.

Thanks for explaining.  That makes things a bit clearer.

> Actually it's a bit tricky in pure xslt 1 to sort and then access the
> sorted list at the same time, as the sorted list information goes to the
> result tree where by design you can't really get it back.

I'm somewhat relieved to hear that what I'm trying to do is "a bit
tricky", as it wasn't at all obvious to me how to proceed.  I have 20+
years of experience programming in procedural languages and certainly
understand things like recursion and iteration, but sometimes it feels
like those years of procedural experience are more a hindrance than a
help, at least as far as XSLT.  ;-)

> If you can use your processor's node-set extension (if it has one) first
> sort the input into a temporary variable then process every other item
> in this sorted list, and access the next item by
> following-sibling::*[1]
> if xx:node-set() isn't available, ask again:-)

I've been using xsltproc from libxslt 1.1.5, but that's only because it's
installed on my workstation and has a good reputation.

Searching on the libxslt site, it appears to have at least some support
for the EXSLT extenions, including exsl:node-set.  I'll see how far I
can get with the excellent tips you've provided.

Thanks much!

Tim Mooney                              mooney@dogbert.cc.ndsu.NoDak.edu
Information Technology Services         (701) 231-1076 (Voice)
Room 242-J6, IACC Building              (701) 231-8541 (Fax)
North Dakota State University, Fargo, ND 58105-5164

This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

Received on Wednesday, 13 October 2004 15:43:31 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 3 October 2007 16:06:13 GMT