[
Lists Home |
Date Index |
Thread Index
]
The purpose is to generate a single xml file in which I can apply an xsl
that we have that generates a matrix table comparrison of the two vehicles.
So its important that each vehicle have the same nodes whether empty or not.
In the example since the <header header_name="Misc"> node had the same row
nodes in both xml's that was not merged. If xml 2 has a header node that
xml1 does not have then that would have to be merged as well.
Here is my xsl at this point.
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:apply-templates select="vehicle" />
</xsl:template>
<xsl:template match="vehicle">
<xsl:variable name="xml2" select="document('xml2.xml')" />
<vehicles>
<vehicle>
<xsl:attribute name="aic_id"><xsl:value-of select="@aic_id"
/></xsl:attribute>
<make>
<xsl:apply-templates select="make" mode="copy" />
</make>
<year>
<xsl:apply-templates select="year" mode="copy" />
</year>
<model>
<xsl:apply-templates select="model" mode="copy" />
</model>
<style>
<xsl:apply-templates select="style" mode="copy" />
</style>
<image>
<xsl:apply-templates select="image" mode="copy" />
</image>
<headers>
<xsl:for-each select="$xml2//headers/header">
<xsl:if test="@header_name=$xml2//@header_name">
<xsl:variable name="bcheck">true</xsl:variable>
</xsl:if>
<xsl:if test="@bcheck='true'">
<header>
<xsl:attribute name="header_name"><xsl:value-of
select="$xml2//@header_name"/></xsl:attribute>
</header>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="//headers/header">
<xsl:variable name="current_header" select="@header_name" />
<header>
<xsl:attribute name="header_name"><xsl:value-of
select="@header_name"/></xsl:attribute>
<xsl:for-each
select="//headers/header[@header_name=($current_header)]/rows/row">
<row>
<xsl:attribute name="rows_name"><xsl:value-of select="@row_name"
/></xsl:attribute>
<xsl:value-of
select="//headers/header[@header_name=($current_header)]/rows/row" />
</row>
</xsl:for-each>
</header>
</xsl:for-each>
</headers>
</vehicle>
<vehicle>
<xsl:attribute name="aic_id"><xsl:apply-templates
select="document(xml2.xml)[@aic_id]" mode="copy"/></xsl:attribute>
<xsl:copy-of select="$xml2//make" />
<xsl:copy-of select="$xml2//year" />
<xsl:copy-of select="$xml2//model" />
<xsl:copy-of select="$xml2//style" />
<xsl:copy-of select="$xml2//image" />
<headers>
<xsl:for-each select="$xml2//headers/header">
<header>
<xsl:attribute name="header_name"><xsl:apply-templates
select="$xml2//@header_name"/></xsl:attribute>
</header>
</xsl:for-each>
<xsl:for-each select="//headers/header">
<header>
<xsl:if test="$xml2//headers/header[@header_name!=@header_name]">
<xsl:attribute name="header_name"><xsl:value-of
select="@header_name"/></xsl:attribute>
</xsl:if>
</header>
</xsl:for-each>
</headers>
</vehicle>
</vehicles>
</xsl:template>
</xsl:stylesheet>
----Original Message Follows----
From: Robin LaFontaine <robin.lafontaine@deltaxml.com>
You seem to have in your output a <vehicle> for each of the input <vehicle>
elements, but the <header name="Safety"> seem to have been merged in the two
cases, whereas the <header name="Misc"> is not merged. This suggests you
have very specific needs here.
One other small point: suggest you use xsl:strip-space to get rid of the
spurious indentation (perhaps the files are not indented in originals).
Hope this helps a little.
Robin La Fontaine
[1] http://www.deltaxml.com
At 2:50 pm -0500 11/9/02, Dave Yancey wrote:
>I'm trying to combine two xml files into a single xml file via xslt. I know
>how to do it using copy-of but certain requirments must be met.
>
>The two xml files are vehicle features. And are similiar.
>
>In the xml there are header nodes and row nodes.
>
>xml1 may contain certain header nodes and row nodes that xml2 doesn't.
>
>In the resulting xml each vehicle must contain the same header and row
>nodes with the correct values (empty or their existing values).
>
>Here is an example of each xml file and what the result is supposed to look
>like.
>
...cut
>-----------------------------------------------------------------
>The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
>initiative of OASIS <http://www.oasis-open.org>
>
>The list archives are at http://lists.xml.org/archives/xml-dev/
>
>To subscribe or unsubscribe from this list use the subscription
>manager: <http://lists.xml.org/ob/adm.pl>
--
-- -----------------------------------------------------------------
Robin La Fontaine, Director, Monsell EDM Ltd
DeltaXML: "Change control for XML, in XML"
Tel: +44 1684 592 144 Fax: +44 1684 594 504
Email: robin.lafontaine@deltaxml.com http://www.deltaxml.com
-----------------------------------------------------------------
The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
initiative of OASIS <http://www.oasis-open.org>
The list archives are at http://lists.xml.org/archives/xml-dev/
To subscribe or unsubscribe from this list use the subscription
manager: <http://lists.xml.org/ob/adm.pl>
----
David Yancey
_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx
|