Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT sorting / merging / summing

Reply
Thread Tools

XSLT sorting / merging / summing

 
 
david.paik@huscointl.com
Guest
Posts: n/a
 
      09-20-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
merging 2 csv files and sorting merged file Askar Ka Ruby 2 05-01-2011 08:50 AM
sorting and merging of arrays of unknown sizes ramu C Programming 2 11-16-2009 06:52 PM
sorting/merging in C Osiris C Programming 6 06-17-2007 09:07 AM
xslt merging question rottyguy70@yahoo.com XML 4 11-01-2005 05:14 PM
Merging two XML tree: xslt or dom ? Yannick Patois XML 1 07-23-2004 07:17 PM



Advertisments