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

Re: Document summary using xsl:key

Subject: Re: Document summary using xsl:key
From: Mukul Gandhi <mukulw3@xxxxxxxxx>
Date: Thu, 24 Jul 2003 10:19:41 -0700 (PDT)
summary gandhi
Hi Rob,
Please try this slightly modified XSL..

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>
  <xsl:key name="x"
match="Invoice/InvoiceLineItem/MonetaryAdjustment/TaxAdjustment"
use="@Code"/>

  <xsl:template match="Invoice">
    <summary>
      <xsl:apply-templates
select="InvoiceLineItem/MonetaryAdjustment/TaxAdjustment"
/>
    </summary>
  </xsl:template>
      
  <xsl:template
match="InvoiceLineItem/MonetaryAdjustment/TaxAdjustment">
    <xsl:if test="generate-id(.) =
generate-id(key('x', @Code)[1])">
	<xsl:variable name="N" select="@Code"/>
	<xsl:variable name="R"
select="TaxPercent/MeasurementValue"/>
	<xsl:variable name="C"
select="count(/Invoice/InvoiceLineItem/MonetaryAdjustment/TaxAdjustment[@Code
= $N])"/>
	<xsl:variable name="V"
select="sum(/Invoice/InvoiceLineItem/MonetaryAdjustment/TaxAdjustment[@Code
= $N]/TaxValue)"/>
	<tax code="{$N}" count="{$C}" rate="{$R}"
tax="{$V}"/>
   </xsl:if>
</xsl:template>
</xsl:stylesheet>

Regards,
Mukul

--- Rob Anderson <roba@xxxxxxxxxx> wrote:
> 
> Help!
> 
> I am really struggling with this...
> 
> I have the following XML
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <Invoice>
> 	<InvoiceLineItem>
> 		<MonetaryAdjustment>
> 			<TaxAdjustment Code="Standard">
> 				<TaxPercent>
> 					<MeasurementValue>17.50</MeasurementValue>
> 				</TaxPercent>
> 				<TaxValue>1.00</TaxValue>
> 			</TaxAdjustment>
> 		</MonetaryAdjustment>
> 	</InvoiceLineItem>
> 	<InvoiceLineItem>
> 		<MonetaryAdjustment>
> 			<TaxAdjustment Code="Zero">
> 				<TaxPercent>
> 					<MeasurementValue>0.0</MeasurementValue>
> 				</TaxPercent>
> 				<TaxValue>2.00</TaxValue>
> 			</TaxAdjustment>
> 		</MonetaryAdjustment>
> 	</InvoiceLineItem>
> 	<InvoiceLineItem>
> 		<MonetaryAdjustment>
> 			<TaxAdjustment Code="Standard">
> 				<TaxPercent>
> 					<MeasurementValue>17.50</MeasurementValue>
> 				</TaxPercent>
> 				<TaxValue>3.00</TaxValue>
> 			</TaxAdjustment>
> 		</MonetaryAdjustment>
> 	</InvoiceLineItem>
> </Invoice>
> 
> I am trying to create a summary XML document
> 
> <summary>
> 	<tax code="Standard" count="2" rate="17.50"
> tax="3.00"/>
> 	<tax code="Zero" count="1" rate="0.0" tax="0.00"/>
> </summary>
> 
> My stylesheet is: -
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 	<xsl:output method="xml" indent="yes"/>
> 	<xsl:key name="x"
>
match="Invoice/InvoiceLineItem/MonetaryAdjustment/TaxAdjustment"
> use="@Code"/>
> 	<xsl:template match="/">
> 		<summary>
> 			<xsl:for-each
>
select="Invoice/InvoiceLineItem[generate-id(MonetaryAdjustment/TaxAdjustment
> /@Code) = generate-id(key('x', @Code)[1])]">
> 				<xsl:variable name="N"
> select="MonetaryAdjustment/TaxAdjustment/@Code"/>
> 				<xsl:variable name="R"
>
select="MonetaryAdjustment/TaxAdjustment/TaxPercent/MeasurementValue"/>
> 				<xsl:variable name="C"
>
select="count(/Invoice/InvoiceLineItem/MonetaryAdjustment/TaxAdjustment[@Cod
> e= $N])"/>
> 				<xsl:variable name="V"
>
select="sum(/Invoice/InvoiceLineItem/MonetaryAdjustment/TaxAdjustment[@Code=
> $N]/TaxValue)"/>
> 				<tax code="{$N}" count="{$C}" rate="{$R}"
> tax="{$V}"/>
> 			</xsl:for-each>
> 		</summary>
> 	</xsl:template>
> </xsl:stylesheet>
> 
> 
> However, being a complete novice on the use of 'key'
> I achieve nothing,
> other than a very nice xml prolog!.
> 
> Any help, preferably a modified XSL, and I would be
> eternally grateful.
> 
> Rob
> 
> 
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.