xsl-list
[Top] [All Lists]

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

2007-10-02 05:24:28
 
I want to generate some numeric attributes in the output document and I
want to control the numbering using attributes in the input document.
It seems to me that I need to be able to refer to numbers in the result
tree, which I don't think is possible in xsl.
Alternatively if I was doing this in a conventional programming language
I'd have a variable which I'd use for allocating numbers, but xsl
famously has "assign-once" semantics for its variables, requiring
iterations like this to be done in a different way.
 
 
1.
Simple Count.  Just add a field to the result document with an
incrementing index.
I know how to do this (its in D.Pawson's Questions and Answers):
<xsl:value-of select="count(preceding::*) + 1" />
 
<incoming name="a"/> 
<incoming name="b"/> 
<incoming name="c"/>
 
<outgoing name="a" index="1" /> 
<outgoing name="b" index="2" /> 
<outgoing name="c" index="3" /> 
 
This is simple as the output numbers are related entirely to the inputs,
with no need to refer to other outputs.
 
2.
Count with specification of sizes.
In this case the nodes in the incoming document may include an attribute
to indicate that they need to allocate more than one number.
 
<incoming name="a" /> 
<incoming name="b" size="4" /> 
<incoming name="c" /> 
<incoming name="d" size="2" /> 
<incoming name="e" />
 
<outgoing name="a" index="1" /> 
<outgoing name="b" index="2" /> 
<outgoing name="c" index="6" /> 
<outgoing name="d" index="7" /> 
<outgoing name="e" index="9" />
 
So, the logic here is :
If the previous input node doesn't have a "size" attribute, the number
for this output node is the previous output node's number plus one. 
If the previous input node does have a "size" attribute, the number for
this output node is the previous output node's number plus the previous
input node's "size".  (This second rule covers the first rule if we also
say that if the previous input node doesn't have a "size" attribute, its
size should be considered to be one)
 
 
3.
Count allowing numbers to be specified in the input document.
 
<incoming name="a" /> 
<incoming name="b" index="42" /> 
<incoming name="c" /> 
<incoming name="d" index="100" /> 
<incoming name="e" />
 
<outgoing name="a" index="1" /> 
<outgoing name="b" index="42" /> 
<outgoing name="c" index="43" /> 
<outgoing name="d" index="100" /> 
<outgoing name="e" index="101" />
 
 
The logic here is :
If the current input node has an "index" attribute, copy it for the
current output node.
If the current input node does not have an "index" attribute, the
current output node should be given an "index" equal to the previous
output node's "index" plus one.
 
 
I am assuming that there is a way to do this using xsl but I'm fairly
new to it and can't think of how to do this using the parts of the
language I know.  Can anyone suggest ways I might achieve it ?
 
 
 
Regards,
Richard.
 
 

Richard Kerry
Colledia Control Engineer
Siemens IT Solutions and Services Ltd

This e-mail contains confidential information and is for the exclusive
use of the addressee/s.  If you are not the addressee, then any
distribution, copying or use of this e-mail is prohibited. If received
in error, please advise the sender and delete it immediately.  We accept
no liability for any loss or damage suffered by any person arising from
use of this e-mail.

Siemens IT Solutions and Services Limited
Registered No: 1203466 England
Registered Office: Faraday House, Sir William Siemens Square, Frimley,
Camberley, GU16 8QD

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--