xsl-list
[Top] [All Lists]

RE: Merging Data

2004-08-06 13:04:14
Thank you

-----Original Message-----
From: Michael Kay [mailto:mhk(_at_)mhk(_dot_)me(_dot_)uk] 
Sent: 06 August 2004 18:25
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Merging Data

Try changing 

current-group() intersect $list1

to

(current-group() intersect $list1)/supp-price

(The members of the group are supp elements, whereas we want to output
the
value of the supp-price elements).

Michael Kay 

-----Original Message-----
From: Kevin Bird (Matrix) 
[mailto:kevin(_dot_)bird(_at_)matrixdigitaldata(_dot_)co(_dot_)uk] 
Sent: 06 August 2004 17:21
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Merging Data

Hi Michael

I ran your XSLT 2.0 solution against my data and produced the 
following
output. The text value of <supp-desc> is also appearing in 
<supp-price>
(which is not required). I've had a play around with the 
stylesheet but I'm
stabbing around in the dark.

Any suggestions would be greatly appreciated.


<?xml version="1.0" encoding="UTF-8"?>
<supp>
   <supp-desc>Half Board</supp-desc>
   <supp-price source="filea">Half Board£10</supp-price>
   <supp-price source="fileb">Half Board£20</supp-price>
</supp>
<supp>
   <supp-desc>All Inclusive</supp-desc>
   <supp-price source="filea">All Inclusive£20</supp-price>
   <supp-price source="fileb">All Inclusive£40</supp-price>
</supp>
<supp>
   <supp-desc>Sea View</supp-desc>
   <supp-price source="filea">Sea View£3</supp-price>
   <supp-price source="fileb">-</supp-price>
</supp>
<supp>
   <supp-desc>Balcony</supp-desc>
   <supp-price source="filea">-</supp-price>
   <supp-price source="fileb">Balcony£5</supp-price>
</supp>

Many thanks.

--
Kevin Bird



-----Original Message-----
From: Michael Kay [mailto:mhk(_at_)mhk(_dot_)me(_dot_)uk] 
Sent: 05 August 2004 18:44
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Merging Data

It's a grouping problem, with the extra complication that you 
can't rely on
the relative document order of nodes from two different 
documents. XSLT 2.0
solution:

<xsl:variable name="list1" select="doc('1.xml')/*/supp"/> 
<xsl:variable
name="list2" select="doc('2.xml')/*/supp"/>

<xsl:for-each-group select="$list1, $list2"
                    group-by="supp-desc">
  <supp>
    <xsl:copy-of select="supp-desc"/>
    <supp-price source="filea">
      <xsl:value-of select="(current-group() intersect 
$list1, '-')[1]"/>
    </supp-price> 
    <supp-price source="fileb">
      <xsl:value-of select="(current-group() intersect 
$list2, '-')[1]"/>
    </supp-price>
  </supp>
</xsl:for-each-group>

I will leave the XSLT 1.0 solution to someone with more time 
on their hands.
It's tricky because both grouping mechanisms 
(preceding-sibling and keys)
work only within a single document, so you have to use a 
two-phase approach.

Michael Kay

-----Original Message-----
From: Kevin Bird 
[mailto:kevin(_dot_)bird(_at_)matrixdigitaldata(_dot_)co(_dot_)uk]
Sent: 05 August 2004 18:20
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Merging Data

Hi Everyone

I need to combine two sets of data (File A and File B). The 
structure 
is as follows (snippet):

FILE A:
<supplements>
<supp>
    <supp-desc>Half Board</supp-desc>
    <supp-price>£10</supp-price>
</supp>
<supp>
    <supp-desc>All Inclusive</supp-desc>
    <supp-price>£20</supp-price>
</supp>
<supp>
    <supp-desc>Sea View</supp-desc>
    <supp-price>£3</supp-price>
</supp>
...
</supplements>

FILE B:
<supplements>
<supp>
    <supp-desc>Half Board</supp-desc>
    <supp-price>£20</supp-price>
</supp>
<supp>
    <supp-desc>All Inclusive</supp-desc>
    <supp-price>£40</supp-price>
</supp>
<supp>
    <supp-desc>Balcony</supp-desc>
    <supp-price>£5</supp-price>
</supp>
...
</supplements>

REQUIRED OUTPUT:
<supplements>
<supp>
    <supp-desc>Half Board</supp-desc>
    <supp-price source="filea">£10</supp-price>
    <supp-price source="fileb">£20</supp-price> </supp> <supp>
    <supp-desc>All Inclusive</supp-desc>
    <supp-price source="filea">£20</supp-price>
    <supp-price source="fileb">£40</supp-price> </supp> <supp>
    <supp-desc>Sea View</supp-desc>
    <supp-price source="filea">£3</supp-price>
    <supp-price source="fileb">-</supp-price></supp>
<supp>
    <supp-desc>Balcony</supp-desc>
    <supp-price source="filea">-</supp-price>
    <supp-price source="fileb">£5</supp-price></supp>
...
</supplements>

DESCRIPTION:
I need to compare <supp> nodes based on the text value of 
<supp-desc>. 
If the <supp> exists in both files then the <supp-price> node from 
File B is added underneath the <supp-price> node from File A (a 
"source" attribute is also added). If the <supp> exists in one file 
but not the other, a <supp-price> node with the text value 
of "-" is 
added. "Sea View" and "Balcony" are examples of <supp> 
being present 
in one file only.

Any suggestions on how best to achieve the desired result will be 
greatly appreciated.

 
--
Kevin Bird


--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--




--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--





--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--




--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--






<Prev in Thread] Current Thread [Next in Thread>