xsl-list
[Top] [All Lists]

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

2011-01-06 08:22:53
Hi David,

I made a mistake in that match pattern by trying to simplify the xml source.  
I'm using xslt2.0 (saxon).

Here is original xml before transformation:

<LeafExtName id="Cap">
  <MaterialGroup id="Filler">
    <MatClassDess matgchild="0" id="Glass Fibrous" extchild="0">
      <MassPercent>30.35</MassPercent>
    </MatClassDess>
  </MaterialGroup>
  <MaterialGroup id="Flame retardant">
    <MatClassDess matgchild="0" id="Antimony trioxide (Sb2O3)" extchild="1">
      <MassPercent>30.35</MassPercent>>
    </MatClassDess>
  </MaterialGroup>
  <MaterialGroup id="Polymer">
    <MatClassDess matgchild="0" id="Polybutylene terephthalate" extchild="2">
      <MassPercent>20.50</MassPercent>
    </MatClassDess>
  </MaterialGroup>
  <MaterialGroup id="Pigment">
    <MatClassDess matgchild="0" id="Not disclosed by Subco." extchild="3">
      <MassPercent>08.80</MassPercent>
    </MatClassDess>
  </MaterialGroup>
</LeafExtName>

In my current xslt I have following which i think is the same as you proposed 
but that does not work. See outcome below.

  <xsl:template 
match="MassPercent[max(ancestor::LeafExtName/MaterialGroup/MatClassDess/MassPercent)
 = .][1]" mode="fixpercentages">
    <MassPercent>TODO</MassPercent>
  </xsl:template>

Result after transformation:

<LeafExtName id="Cap">
  <MaterialGroup id="Filler">
    <MatClassDess matgchild="0" id="Glass Fibrous" extchild="0">
      <MassPercent>TODO</MassPercent>
    </MatClassDess>
  </MaterialGroup>
  <MaterialGroup id="Flame retardant">
    <MatClassDess matgchild="0" id="Antimony trioxide (Sb2O3)" extchild="1">
      <MassPercent>TODO</MassPercent>>
    </MatClassDess>
  </MaterialGroup>
  <MaterialGroup id="Polymer">
    <MatClassDess matgchild="0" id="Polybutylene terephthalate" extchild="2">
      <MassPercent>20.50</MassPercent>
    </MatClassDess>
  </MaterialGroup>
  <MaterialGroup id="Pigment">
    <MatClassDess matgchild="0" id="Not disclosed by Subco." extchild="3">
      <MassPercent>08.80</MassPercent>
    </MatClassDess>
  </MaterialGroup>
</LeafExtName>

So adding [1] to the predicate does not work unfortunately.

Robby

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