xsl-list
[Top] [All Lists]

[xsl] match first occurrence for which a condition holds true

2011-01-06 08:06:04
Hi all,

i'm struggling a bit with following simplified use case. I have a subpart which 
consists of 1 or more materialgroups and a materialgroup consists of 1 or more 
materials.  They all have a percentage (measured on subpart level). Sometimes 
the sum of these percentages doesn't add up to 100% so the customer wants me to 
correct the largest [first matching] percentage so that the total percentages 
add up to 100.  

I am able to match on the percentages which match the maximum in the context of 
subpart but in example below i match on both lead and trioxide whereas i only 
need to fix the first occurence which is lead in this case.

How can i solve this elegantly?

Kind regards,
Robby Pelssers

  <xsl:template 
match="MassPercent[max(ancestor::subpart/materialgroup/material/percentage) = 
.]" mode="fixpercentages">
    <percentage>fix me</percentage>
  </xsl:template>

<subpart>
  <materialgroup>
    <material name="lead">
      <percentage>35.30</percentage>
    </material>
  </materialgroup>
  <materialgroup>
    <material name="trioxide">
      <percentage>35.30</percentage>
    </material>
    <material name="Polybutylene">
      <percentage>20.50</percentage>
    </material>
  </materialgroup>
  <materialgroup>
    <material name="Glass Fibrous">
      <percentage>08.80</percentage>
    </material>
  </materialgroup>
</subpart>
  

--~------------------------------------------------------------------
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>
--~--