[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Muenchian troubles - only getting first group - Help

Subject: Muenchian troubles - only getting first group - Help please!
From: thehulk@xxxxxxxxxxx
Date: Tue, 6 Sep 2011 05:10:22 +0000 (UTC)
 Muenchian troubles - only getting first group - Help
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. )

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.