Go Back   Velocity Reviews > Newsgroups > XML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

XML - XSLT sorting / merging / summing

 
Thread Tools Search this Thread
Old 09-20-2006, 03:12 PM   #1
Default XSLT sorting / merging / summing


Given the data:

<?xml version="1.0" encoding="UTF-8"?>

<?xml-stylesheet type="text/xsl" href="C:\junk\830new.xslt"?>

<SC830>

<SC830_3 bano="S67777" cuno="002620" year="2007" week="38"
item="282-333" qty="10" PO1="PO242" PO2="PO343" PO3="" PO4=""
PO5="PO555" PO6="" PO7=""/>

<SC830_3 bano="S67777" cuno="002620" year="2007" week="38"
item="282-333" qty="12" PO1="PO242" PO2="PO343" PO3="" PO4="PO444"
PO5="" PO6="" PO7=""/>

<SC830_3 bano="S67777" cuno="002620" year="2007" week="44"
item="282-666" qty="20" PO1="PO242" PO2="PO343" PO3="" PO4="" PO5=""
PO6="" PO7=""/>

</SC830>

I want the 1st and 2nd elements merged, and the qty summed.

I got close:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="2.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlnss="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions">

<xslutput method="text" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:key name="linekey" match="SC830_3"
use="concat(@bano,'*',@cuno,'*',@year,'*',@week,'* ',@item,'*')"/>

<xsl:template match="SC830">

<xsl:apply-templates select="SC830_3[count(.|key('linekey',
concat(@bano,'*',@cuno,'*',@year,'*',@week,'*',@it em,'*'))[1]) = 1]"/>

</xsl:template>

<xsl:template match="SC830_3">

<xsl:copy-of
select="concat(@bano,'*',@cuno,'*',@year,'*',@week ,'*',@item,'*')" />

<xsl:value-of select="sum(key('linekey',
concat(@bano,'*',@cuno,'*',@year,'*',@week,'*',@it em,'*'))/@qty)" />*

<xsl:value-of select="key('linekey',
concat(@bano,'*',@cuno,'*',@year,'*',@week,'*',@it em,'*'))/@PO1[string-length(.)
&gt; 0]"/>*

<xsl:value-of select="key('linekey',
concat(@bano,'*',@cuno,'*',@year,'*',@week,'*',@it em,'*'))/@PO2[string-length(.)
&gt; 0]" />*

<xsl:value-of select="key('linekey',
concat(@bano,'*',@cuno,'*',@year,'*',@week,'*',@it em,'*'))/@PO3[string-length(.)
&gt; 0]" />*

<xsl:value-of select="key('linekey',
concat(@bano,'*',@cuno,'*',@year,'*',@week,'*',@it em,'*'))/@PO4[string-length(.)
&gt; 0]" />*

<xsl:value-of
select="key('linekey',concat(@bano,'*',@cuno,'*',@ year,'*',@week,'*',@item,'*'))/@PO5[string-length(.)
&gt; 0]" />*

<xsl:value-of select="key('linekey',
concat(@bano,'*',@cuno,'*',@year,'*',@week,'*',@it em,'*'))/@PO6[string-length(.)
&gt; 0]" />*

<xsl:value-of select="key('linekey',
concat(@bano,'*',@cuno,'*',@year,'*',@week,'*',@it em,'*'))/@PO7[string-length(.)
&gt; 0]" />*

<xsl:text>

</xsl:text>

</xsl:template>

</xsl:stylesheet>



This gives me:

S67777*002620*2007*38*282-333*22*

PO242 PO242*

PO343 PO343*

*

PO444*

PO555*

*

*


S67777*002620*2007*44*282-666*20*

PO242*

PO343*

*

*

*

*

*



So the QTYs sum ok and I get the right amount of lines. But I still
have an issue with the PO attributes. I get:

PO242 PO242*

PO343 PO343*

and I just want:

PO242*

PO343*

I tried putting a [1] in but that returns the same thing.

IDEAS?

I am sure there are some XML experts out there that can solve this
delema!

Thanks!

DP



david.paik@huscointl.com
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump