xsl-list
[Top] [All Lists]

[xsl] Muenchian troubles - only getting first group - Help please!

2011-09-06 00:10:37


I am having trouble with Muenchian grouping. I want to add up the charges, by 
type. I expect in this particular example to output two <Total_Charge_By_Type 
... /> elements, but only one is outputted! 

Here is the example XML :

<Account>
  <Service Name="A Service" Service_Id="89150" >
        <Feature Name="Extents" Feature_Id="203943" Status="65">
                <Charge Trans_Type_Name="Extent" Bucket_Type="1">
                        <Trans_Class>R</Trans_Class>
                        <Charge_Amount>
                                <Amount Currency_Cd="EUR">467.55</Amount>
                        </Charge_Amount>
                </Charge>
        </Feature>
        <Feature Name="Service Accumulator" Feature_Id="567528" Status="65">
          <Total_Charge>
                <Charge_Amount>
                        <Amount Currency_Cd="EUR">0</Amount>
                </Charge_Amount>
          </Total_Charge>
        </Feature>
        <Feature Name="Storage" Feature_Id="267663" Status="65">
                <Charge Trans_Type_Name="Pages" Bucket_Type="1">
                        <Trans_Class>R</Trans_Class>
                        <Charge_Amount>
                                <Amount Currency_Cd="EUR">16.64</Amount>
                        </Charge_Amount>
                </Charge>
                <Charge Trans_Type_Name="Pages" Bucket_Type="1">
                        <Trans_Class>R</Trans_Class>
                        <Charge_Amount>
                                <Amount Currency_Cd="EUR">0.64</Amount>
                        </Charge_Amount>
                </Charge>
        </Feature>
  </Service>
</Account>


In the template that processes the <Account>, the Account is current at that 
time it calls the template "muench_chargetypenames" to do the summing: 

....
<!-- Now, Add up and nest in the Charges within the Services within this 
Account                -->
        <xsl:if test="Service">
                <xsl:element name="Total_Charge">
                        <xsl:attribute  name="Amount"> 
                                <xsl:value-of select=
"sum( Service//Charge[not(Trans_Class=&quot;I&quot;)]/Charge_Amount/Amount)" />
                        </xsl:attribute>        
                        <xsl:attribute name="Flag" >
                                <xsl:value-of select="HasSvc" />
                        </xsl:attribute>        
                </xsl:element>
<!-- Also, add up and nest in the Charges divided into separate Transaction 
type names  --> 
                <xsl:call-template name="muench_chargetypenames"/>
        </xsl:if>       
        <xsl:if test="not(Service)">
<Total_Charge Amount="0" Flag="NoSvc" />                        
        </xsl:if>
.....

The key is defined according to the attribute @Trans_Type_Name of the Charge 
element:

<xsl:key name="TransTypes" 
        match="Charge[Trans_Class='R']" 
        use="@Trans_Type_Name"/>


And here is muench_chargetypenames :

<xsl:template name="muench_chargetypenames" >   
        <xsl:message>
Hey, in muench_chargetypenames 
Current element name <xsl:value-of select="local-name(.)"/>
        </xsl:message>  
        <xsl:for-each 
select="Service/Feature/Charge[generate-id()=generate-id(key('TransTypes',@Trans_Type_Name)[1])]">
                <xsl:variable name="ThisType" 
select="@Trans_Type_Name"></xsl:variable>
                <xsl:message>                   
Hey, Total By Type, type is  <xsl:value-of select="@Trans_Type_Name"/> ,  
Amount of this one is  <xsl:value-of select="Charge_Amount/Amount"/>            
              
                </xsl:message>                   
                <xsl:element name="Total_Charge_By_Type">
                        <xsl:attribute name="Amount"> 
                          <xsl:value-of select=
"sum(../../../Service/Feature/Charge[Trans_Class='R' and 
@Trans_Type_Name=$ThisType]/Charge_Amount/Amount)" />
                        </xsl:attribute>        
                        <xsl:attribute name="Trans_Type_Name" >
                                <xsl:value-of select="@Trans_Type_Name" />
                        </xsl:attribute>        
                </xsl:element>
        </xsl:for-each>
</xsl:template> 


The message output shows that the for-each is looping only once, for type 
"Pages", but there should be a second time for "Extent". Why not? 

( There could have been more Services, but in this example there are not.)
( I could have used ancestors::Account instead of ../../.. , but that part is 
working. )


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