Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Re: XSLT - Combining elements based on their content

Reply
Thread Tools

Re: XSLT - Combining elements based on their content

 
 
Peter Flynn
Guest
Posts: n/a
 
      04-11-2004
Tony wrote:
> Hi all.
>
> I'll explain what we're doing first by way of an example before asking
> about the XSLT.
>
> We order 10 pallets of ABC and 20 pallets of XYZ.
> 10 X ABC costs $XXX and 20 X XYZ costs $YYY.
> In the confirmation we get back from the supplier we get the order
> back plus extra data that we need but it occurs more than once.
>
> So the confirmation comes back with:
> 10 X ABC = $XXX
> 20 X XYZ = $YYY
> 10 X pallet = $10
> 20 X pallet = $20


They *charge* you for the pallets?

> Each of these items comes back as an <OrderLine /> with specific
> details attached, like weight, unit price, currency, product number,
> etc)


This looks like a classical piece of accountants' XML. Unfortunately
some of the people working on systems like this need some significantly
better training. Better still, keep the accountants well away from the
markup if you can

> I need to translate the incoming order confirmation using XSLT into
> OrderLines based on the product number (only 1 per orderline),
> checking that the unit price is the same.


Without seeing the markup, I can only guess at what you mean. Let's
assume you have something like

<order>
<orderline q="10" prod="ABC" unit="5"/>
<orderline q="20" prod="XYZ" unit="10"/>
<orderline q="10" prod="pallet" unit="1"/>
<orderline q="20" prod="pallet" unit="1"/>
</order>

> eg. In the above example the pallets would have the same product
> number and same unit price ($1 each) therefore they would be appended
> to make 30 X pallet = $30.
>
> ie. I need a document that comes back with:
>
> 10 X ABC = $XXX
> 20 X XYZ = $YYY
> 30 X pallet = $30
>
> I've tried various means even grouping but it just doesn't seem to
> work.


<xsl:template match="order">
<order>
<xsl:apply-templates/>
</order>
</xsl:template>

<xsl:template match="orderline">
<xsl:if test="count(following-sibling:rderline)=0 or
following-sibling:rderline/@prod!=current()/@prod">
<orderline prod="{@prod}" unit="{@unit}">
<xsl:attribute name="q">
<xsl:value-of
select="sum(../orderline[@prod=current()/@prod]/@q)"/>
</xsl:attribute>
</orderline>
</xsl:if>
</xsl:template>

///Peter

 
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
error: Only Content controls are allowed directly in a content page that contains Content controls. hazz ASP .Net 6 06-09-2010 01:54 PM
XSLT: Generating a format mask string based on the content of a node? Dag Sunde XML 7 03-10-2007 10:06 PM
Is there any c++ based XSLT processor which conforms to XSLT 2.0 vaibhav XML 3 08-14-2006 09:03 AM
XSLT: iterating all child elements and accessing homonymous childrenin sibling elements Gerald Aichholzer XML 2 06-27-2006 03:46 PM
XSLT: remove multiple elements having same child element content Johannes Koch XML 1 03-05-2004 02:30 PM



Advertisments