[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Using the Input Document to Control Generation of

Subject: Re: Using the Input Document to Control Generation of Numbers in the Output
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 02 Oct 2007 19:50:16 +0200
Re:  Using the Input Document to Control Generation of
Kerry, Richard wrote:
I had wondered about the "(@size, 1)[1]" term, which I'd not seen before
but I think I have now worked out.  If there is no "size" attribute, the
term "@size" returns null and thus does not appear as a first node in
the node-set, ie what's within the (), and thus [1] returns what appears
to be the second element, the '1'.

More precisely, in XSLT 2.0 (the above construct will error in XSLT 1.0) is a _sequence_ of items, of which the first item is a selection of an attribute-node and the second item is an integer. When the attribute-node selection returns nothing, the selection will actually return the empty sequence, and indeed, you guessed correctly, empty sequences are folded when they are part of a sequence:


if @size is not there (@size, 1) becomes ((), 1) which then becomes (1).
if @size is there, (@size, 1) will beomce (@size, 1), i.e., it does not change, @size holds the selected attribute-node.


This shortcut is often used, but when you start out with XSLT 2.0, you may prefer the more verbose form:

if (@size) then @size else 1

which is semantically equivalent with (@size, 1)[1].


Cheers, -- Abel --

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.