Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Merge two XML docments with XSLT >Thread Next - Re: Merge two XML docments with XSLT Re: Merge two XML docments with XSLTTo: NULL Date: 9/3/2004 12:02:00 PM Hi Daniel,
Try something like...
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="maps" select="document('maps.xml',/)/maps/element"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="*">
<xsl:variable name="this-element-map" select="$maps[@source =
local-name(current())]"/>
<xsl:choose>
<xsl:when test="$this-element-map">
<xsl:element name="{$this-element-map/@target}">
<xsl:apply-templates select="@*" mode="mapped">
<xsl:with-param name="attributes-map"
select="$this-element-map/attribute"/>
</xsl:apply-templates>
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="@*" mode="mapped">
<xsl:param name="attributes-map"/>
<xsl:variable name="this-attribute-map" select="$attributes-map[@source =
local-name(current())]"/>
<xsl:choose>
<xsl:when test="$this-attribute-map">
<xsl:attribute name="{$this-attribute-map/@target}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:copy/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="@* | text() | comment() | processing-instruction()">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
"Daniel" <softwareengineer98037@y...> wrote in message
news:%23EzPpOWkEHA.524@T......
> Is this possible with an XSLT to merge these two XML documents and get the
> third document? If so any help, guidence, XSLT would be much appreciated!
>
> Maps Document:
>
> <maps>
> <element source="car" target="automobile">
> <attribute source="blue" target="red"/>
> <attribute source="right" target="left"/>
> </element>
> <element source="house" target="close">
> <attribute source="balcony" target="deck"/>
> </element>
> </maps>
>
>
> Data Document:
>
> <top>
> <foo x="1" y="2"/>
> <bar x="1" y="2"/>
> <cars>
> <car blue="1"/>
> </cars>
> <houses>
> <house balcony="true" frontdoor="open"/>
> </houses>
> </top>
>
>
> Desired Target Document After XSLT Transformation
>
> <top>
> <foo x="1" y="2"/>
> <bar x="1" y="2"/>
> <cars>
> <automobile red="1"/>
> </cars>
> <houses>
> <house deck="true"/>
> </houses>
> </top>
>
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
