Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Using the Input Document to Control Generation of Numbers in the Output

From: Abel Braaksma <abel.online@--------->
To:
Date: 10/2/2007 5:52:00 PM
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 --


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent