This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Conditional document merge
- From: Mulberry Technologies List Owner<xsl-list-owner at lists dot mulberrytech dot com>
- To: xsl-list <xsl-list at lists dot mulberrytech dot com>
- Date: Tue, 28 May 2002 11:53:45 -0400
- Subject: RE: [xsl] Conditional document merge
- Reply-to: xsl-list at lists dot mulberrytech dot com
>From: Damon Horrell <dhorrell@oktobor.com>
>To: "'xsl-list@lists.mulberrytech.com'" <xsl-list@lists.mulberrytech.com>
>Subject: RE: [xsl] Conditional document merge
>Date: Tue, 28 May 2002 10:39:36 +1200
>I think this does the sort order you want:
>
> <xsl:template match="/">
>
> <xsl:variable name="docb" select="document('merge-b.xml')"/>
>
> <xsl:for-each select="root/*">
> <xsl:sort select="boolean($docb//*[name() =
>name(current())])" order="descending"/>
> <xsl:sort select="generate-id($docb//*[name() =
>name(current())])"/>
>
> <xsl:value-of select="name()"/>
>
> </xsl:for-each>
>
> </xsl:template>
>
>Run this over document A.
>
>I'll leave the rest to you. Need to remove non-required fields, and get the
>titles from document B as a preference over document A.
>
>Damon
>
> >I've got a more or less classic problem of merging two XML documents. The
>>gotcha's in this case are as follows:
>>
>>1) document A is guaranteed to contain all required nodes, and will include
>>some that are not needed, but the order of the nodes may be out of order.
>>
>>2) document B man not contain all required nodes, if it is missing any,
>some
>>may be flagged as being mandatory in document A, others may be optional and
>>will not be included in the output. Document B will have all nodes in the
>>required order, any missing nodes can be substituted immediately following
>>any previous match. Document B will contain attributes that override any
>>from document A.
>>
>>For example, document A might look like:
>>
>> <root>
>> <a required="1" title="Example 1"/>
>> <b title="Example 2"/>
>> <c title="Example 3"/>
>> <d required="1" title="Example 4"/>
>> <e title="Example 5"/>
>> </root>
>>
>>Document B might look like:
>>
>> <root>
>> <e/>
>> <a title=" New title 1"/>
>> <c/>
>> </root>
>>
>>The required output would be:
>>
>> <root>
>> <e title="Example 5"/>
>> <a title=" New title 1"/>
>> <c title="Example 3"/>
>> <d title="Example 4"/>
>> </root>
>>
>>Where element b is skipped because it is not in document B and is not
>marked
>>as required.
>>
>>Any opinions on what the best way to approach this is? Currently I'm using
>>document B as the primary source and filling in any missing data from
>>Document A as I traverse document B. However, I do not yet handle the case
>>of missing required nodes and I'm not sure how I would pick up on them?
>The
>>alternative of driving things from document A and throwing out the missing
>>not required nodes doesn't seem any simpler, or would there be some elegant
>>way of building a key against document A and then using document B to
>select
>>from it in the proper order automagically skipping the nodes that aren't
> >required and aren't in document B?
>>
>>Peter Hunsberger
>>
>>Phone: 901-495-5252
> >E-mail: Peter.Hunsberger@stjude.org
>
--
======================================================================
B. Tommie Usdin mailto:btusdin@mulberrytech.com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Phone: 301/315-9631
Suite 207 Direct Line: 301/315-9634
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list