|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Document summary using xsl:key
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








