A
arnold
Hi,
I've been knocking my head against the wall trying to create an
XSL transform to perform "normalizations" of a set of XML files
that have a common structure.
% XML file before transform
<base>
<foo>
<bar weight="20">
<elementOne>asfd</elementOne>
<elementTwo>qwer</elementTwo>
</bar>
<bar weight="5">
<elementOne>asfd</elementOne>
<elementTwo>qwer</elementTwo>
</bar>
<bar weight="30">
<elementOne>asfd</elementOne>
<elementTwo>qwer</elementTwo>
</bar>
</foo>
</base>
% XML file after transform
<base>
<foo weightSum="55">
<bar weight="20" lower="1" upper="20">
<elementOne>asfd</elementOne>
<elementTwo>qwer</elementTwo>
</bar>
<bar weight="5" lower="21" upper="25">
<elementOne>asfd</elementOne>
<elementTwo>qwer</elementTwo>
</bar>
<bar weight="30" lower="26" upper="55">
<elementOne>asfd</elementOne>
<elementTwo>qwer</elementTwo>
</bar>
</foo>
</base>
The idea is that a random number between 1 and weightSum would be
selected, and then the child element of the element w/ the weightSum
attribute that has lower<=randomNum<=upper would be selected. This
is a transformation that would only be run when the underlying xml
files
have been updated, so speed of transformation is not an issue.
Constraints: I have many files with this 'weightSum'-'weight' pattern,
and the element names ('foo' and 'bar' in the example above) differ
from file to file. Furthermore, it would be great if the transform
worked on nested 'weightSum'-'weight' patterns, such as the following.
% XML file before transform
<base>
<foo>
<bar weight="20">
<elementOne weight="3">asfd</elementOne>
<elementTwo weight="8">qwer</elementTwo>
</bar>
...
</foo>
</base>
% XML file after transform
<base>
<foo weightSum="55">
<bar weight="20" lower="1" upper="20" weightSum="11">
<elementOne weight="3" lower="1" upper="3">asfd</elementOne>
<elementTwo weight="8" lower="4" upper="11">qwer</elementTwo>
</bar>
...
</foo>
</base>
Any help would be appreciated.
- Arnold
I've been knocking my head against the wall trying to create an
XSL transform to perform "normalizations" of a set of XML files
that have a common structure.
% XML file before transform
<base>
<foo>
<bar weight="20">
<elementOne>asfd</elementOne>
<elementTwo>qwer</elementTwo>
</bar>
<bar weight="5">
<elementOne>asfd</elementOne>
<elementTwo>qwer</elementTwo>
</bar>
<bar weight="30">
<elementOne>asfd</elementOne>
<elementTwo>qwer</elementTwo>
</bar>
</foo>
</base>
% XML file after transform
<base>
<foo weightSum="55">
<bar weight="20" lower="1" upper="20">
<elementOne>asfd</elementOne>
<elementTwo>qwer</elementTwo>
</bar>
<bar weight="5" lower="21" upper="25">
<elementOne>asfd</elementOne>
<elementTwo>qwer</elementTwo>
</bar>
<bar weight="30" lower="26" upper="55">
<elementOne>asfd</elementOne>
<elementTwo>qwer</elementTwo>
</bar>
</foo>
</base>
The idea is that a random number between 1 and weightSum would be
selected, and then the child element of the element w/ the weightSum
attribute that has lower<=randomNum<=upper would be selected. This
is a transformation that would only be run when the underlying xml
files
have been updated, so speed of transformation is not an issue.
Constraints: I have many files with this 'weightSum'-'weight' pattern,
and the element names ('foo' and 'bar' in the example above) differ
from file to file. Furthermore, it would be great if the transform
worked on nested 'weightSum'-'weight' patterns, such as the following.
% XML file before transform
<base>
<foo>
<bar weight="20">
<elementOne weight="3">asfd</elementOne>
<elementTwo weight="8">qwer</elementTwo>
</bar>
...
</foo>
</base>
% XML file after transform
<base>
<foo weightSum="55">
<bar weight="20" lower="1" upper="20" weightSum="11">
<elementOne weight="3" lower="1" upper="3">asfd</elementOne>
<elementTwo weight="8" lower="4" upper="11">qwer</elementTwo>
</bar>
...
</foo>
</base>
Any help would be appreciated.
- Arnold