473,803 Members | 3,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT sorting / merging / summing

Given the data:

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

<?xml-stylesheet type="text/xsl" href="C:\junk\8 30new.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:styleshe et 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(@ba no,'*',@cuno,'* ',@year,'*',@we ek,'*',@item,'* ')"/>

<xsl:template match="SC830">

<xsl:apply-templates select="SC830_3[count(.|key('li nekey',
concat(@bano,'* ',@cuno,'*',@ye ar,'*',@week,'* ',@item,'*'))[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,'*',@ye ar,'*',@week,'* ',@item,'*'))/@qty)" />*

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

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

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

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

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

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

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

<xsl:text>

</xsl:text>

</xsl:template>

</xsl:stylesheet>

This gives me:

S67777*002620*2 007*38*282-333*22*

PO242 PO242*

PO343 PO343*

*

PO444*

PO555*

*

*
S67777*002620*2 007*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 1171

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
5202
by: Ben Fitzgerald | last post by:
Hi I feel I'll be asking for someone to turn water into wine before this happens, but just in case! I'd like to have a page that provides a basic xml document with an xslt that defines the default sorting. Say it's in a table sorted by name with columns age and height. Then, when the user clicks on another column heading, this
3
2888
by: Philipp Lenssen | last post by:
I have this XML file which I would like to XSLT-sort based on the string contained within the item-children elements using basic MSXML (no recent version of IIS, so it might be an outdated MSXML -- pretty sure not MSXML4, though tips on how to do it with that are appreciated too): ----------- Translation Dictionary (German) ---- <?xml version="1.0" encoding="iso-8859-1"?> <items> <item id="4">
1
5076
by: Yannick Patois | last post by:
Hi, I would like to merge two XML document, or more exacly enrich a document by inheritiong from another. I read a bit about XSLT and I know a bit of python/sax/dom, and I dont know where I should go. I tried xslt, without success yet (but I dont know much about it) so I failed back on python+dom wher I know a bit more. I'm asking you if it's a good choice, or if I should use XSLT for this.
4
1479
by: rottyguy70 | last post by:
hello, am trying to do the following with little success. any help is appreciated. 1) assume i have a static mapping: a -> 1 b -> 2 c -> 3 2) i need to read through some data, let's say set and create
2
1527
by: Ryan Adler | last post by:
I have a terrible headache from this problem. Perhaps someone can help. My XML is formatted like this: <events> <event> <starts-at>123456<starts-at/> <event> ... <events/>
2
1738
by: Stefan | last post by:
Hi there! I'm very new to XML and XSLT, so while working i encountered the following, probably very easy to solve, problem. i've got 2 XML-files, which look like this: LinesOfCode.xml: <?xml version="1.0"?> <component name="ORCA_Common">
1
1368
by: zoro | last post by:
there is a property in the book saying: block sorting on P processors using butcher's sort with merging comparators can sort N records in a bout (Log p)2/ 2 parallell sort. and i have question depinding in this property asking how many parellel steps would be required to sort 100,000 records using 32 processors? my answer was (log32) = (1.5)2 = 2.26/2 =1.132 1.132 *100000= 113273.8 is what am doing correct? is it areasonable answer?...
6
2496
by: bcochofel | last post by:
I'm using xsl to list an xml file that contains something like: sites, tag and weight. I'm listing this in a table with the following titles: | URL | TAG | WEIGHT (each title his a link) What I want is when someone clicks a title chooses the sorting option, if this is the actual sorting option then reverses the order. Can I do this? How?
9
2191
by: starlight | last post by:
Hallo, there were some posts about this, but nothing I could find useful. I have a large XML file (80MB) and need certain information out of it. I though I could use XSLT with an fairy simple transformation: .... <xsl:for-each select="/values/STRING/item"> <tr class="own"> <td><xsl:value-of select="A"/></td> <td><xsl:value-of select="B"/></td>
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.