Re: [xsl] more elegant way of doing this? (very simple)

Subject: Re: [xsl] more elegant way of doing this? (very simple)
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 16 Aug 2006 12:54:11 -0400
At 2006-08-16 12:42 -0400, Steve wrote:
Summing up 3 specifically named nodes under Records/Record and summing
them only if they are numbers.

Current XSL===>

sum(Records/Record/*[name(.) = 'AContribution' and number(.) =
number(.) or name(.) = 'BContribution' and number(.) = number(.) or
name(.) = 'CContribution' and number(.) = number(.)])

The following would be more compact:


sum( ( Records/Record/AContribution | Records/Record/BContribution
     | Records/Record/CContribution )[number(.)=number(.)] )

It is not namespace-safe to use name(.).

I'm just trying to reduce redundancy.

You don't say *where* you want to reduce redundancy ... the above syntactically reduces your expression ... I cannot comment on the speed as that would be dependent on your processor so I don't think the question can be answered in that way.

I hope this helps.

. . . . . . . . . . . Ken

--
UBL/XML/XSLT/XSL-FO training:         Verx, Denmark 06-09-25/10-06
World-wide corporate, govt. & user group UBL, XSL, & XML training.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug'05  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread