Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


XSLT to "normalize" weight attribute

From: "arnold" <arnold.juster@-----.--->
To: NULL
Date: 3/2/2006 10:27:00 AM
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



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