Re: XSLT - Combining elements based on their content

Discussion in 'XML' started by Peter Flynn, Apr 11, 2004.

  1. Peter Flynn

    Peter Flynn Guest

    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::eek:rderline)=0 or
    following-sibling::eek: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
     
    Peter Flynn, Apr 11, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BaKMaN
    Replies:
    0
    Views:
    383
    BaKMaN
    Jan 30, 2004
  2. Johannes Koch
    Replies:
    1
    Views:
    819
    Martin Honnen
    Mar 5, 2004
  3. Gerald Aichholzer
    Replies:
    2
    Views:
    2,561
    Gerald Aichholzer
    Jun 27, 2006
  4. vaibhav
    Replies:
    3
    Views:
    1,164
    vaibhav
    Aug 14, 2006
  5. Dag Sunde
    Replies:
    7
    Views:
    1,318
    Dimitre Novatchev
    Mar 10, 2007
Loading...

Share This Page