xsl-list
[Top] [All Lists]

[xsl] XSL For-Each Help!

2006-07-17 12:18:14
Hi All,

Please see the below, I am in desperate need to
resolve this issue and cannot figure it out for the
life of me...

----Problem----:
I am trying to obtain a distinct list of
values('DistributorCodes') for each 'Item' from a
large XML file containing thousands of items.


----Needs-----:
I need to store the result in a variable within my
stylesheet in order to satisfy other dependencies


---Sample XML-----:
<Items>
 <Item ID="1234">
  <ItemsAsMade>
      <ItemAsMade>
         <SupplierCode>SHO</SupplierCode>
         <ItemsAsSold>
            <ItemAsSold>
                <DistributorCode>MEX</DistributorCode>
                <CanOrder>true</CanOrder>
                <CanShip>true</CanShip>
            </ItemAsSold>
            <ItemAsSold>
                <DistributorCode>CAN</DistributorCode>
                <CanOrder>false</CanOrder>
                <CanShip>false</CanShip>
            </ItemAsSold>
            <ItemAsSold>
                <DistributorCode>USA</DistributorCode>
                <CanOrder>true</CanOrder>
                <CanShip>true</CanShip>
            </ItemAsSold>
         </ItemsAsSold>
      </ItemAsMade>
      <ItemAsMade>
         <SupplierCode>SHC</SupplierCode>
         <ItemsAsSold>
            <ItemAsSold>
                <DistributorCode>CAN</DistributorCode>
                <CanOrder>true</CanOrder>
                <CanShip>true</CanShip>
            </ItemAsSold>
            <ItemAsSold>
                <DistributorCode>USA</DistributorCode>
                <CanOrder>false</CanOrder>
                <CanShip>false</CanShip>
            </ItemAsSold>
            <ItemAsSold>
                <DistributorCode>MEX</DistributorCode>
                <CanOrder>false</CanOrder>
                <CanShip>false</CanShip>
            </ItemAsSold>
         </ItemsAsSold>
      </ItemAsMade>
  </ItemsAsMade>
 </Item>
   .....lots more Items...
</Items>


-----My Current Stylesheet snippet-----
<xsl:variable name="distributorVal">    
<!-- only process distributorCodes if canShip and
canOrder are both true -->
   <xsl:for-each
select="//ItemAsMade/ItemsAsSold/ItemAsSold[CanOrderFlag
='true'][CanShipFlag = 'true'][not(DistributorCode =
preceding::DistributorCode)]/DistributorCode">
          <xsl:value-of select="."/>
          <xsl:text>,</xsl:text>
   </xsl:for-each>
</xsl:variable>


---Curent results based on above code------
CAN


---Expected results---------------------
MEX,CAN,USA


---Findings--------------------
It seems that if any second <ItemAsMade> element
within the  <ItemsAsMade> has a 'false' value it
overrides the first <ItemAsMade> even if that one is
set to true, where as if either <ItemAsMade> has both
the canorder and canship flags set to true then that
distributor should be extracted.

---Plea for Help--------------------
PLEASE...PLEASE....can any of you UBER Gods of XSL
help me!!
I have been mucking with this for the past week and
cannot figure it out!


Thanks!!

-Rusty


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

<Prev in Thread] Current Thread [Next in Thread>