Subject: Re: [xsl] Document summary using xsl:key From: Mukul Gandhi <mukulw3@xxxxxxxxx> Date: Thu, 24 Jul 2003 10:19:41 -0700 (PDT) |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Document summary using xsl:ke, Rob Anderson | Thread | RE: [xsl] Document summary using xs, Rob Anderson |
Re: [xsl] saxon:omit-meta-tag attri, David Carlisle | Date | [xsl] Techniques for transforming c, Karr, David |
Month |