Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: "Kerry, Richard" <richard.kerry@----------->
To:
Date: 10/2/2007 12:24:00 PM
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


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