469,612 Members | 2,639 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,612 developers. It's quick & easy.

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"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions">

<xsl:output 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

Sep 20 '06 #1
0 1020

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Ben Fitzgerald | last post: by
3 posts views Thread by Philipp Lenssen | last post: by
1 post views Thread by Yannick Patois | last post: by
4 posts views Thread by rottyguy70 | last post: by
2 posts views Thread by Stefan | last post: by
1 post views Thread by zoro | last post: by
6 posts views Thread by bcochofel | last post: by
9 posts views Thread by starlight | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.