Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: 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/10/2004 11:38:00 AM Hi Daniel,
> Could the same thing be
> done, but with the maps document in side the data document like this:
Yes, just change how the $maps variable is selected, e.g.
change this line...
<xsl:variable name="maps" select="document('maps.xml',/)/maps/element"/>
to...
<xsl:variable name="maps" select="/mapswithdata/maps/element"/>
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:Ovl2V0tlEHA.704@T......
> Thanks! That helped alot! I have another question. Could the same thing be
> done, but with the maps document in side the data document like this:
>
> Data Document (with maps document inside):
>
> <mapswithdata>
> <maps>
> <target id="3" name="UKmusic" />
> <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>
> <top>
> <foo x="1" y="2"/>
> <bar x="1" y="2"/>
> <cars>
> <car blue="1"/>
> </cars>
> <houses>
> <house balcony="true" frontdoor="open"/>
> </houses>
> </top>
> </mapswithdata>
>
>
> Desired Target Document After XSLT Transformation
>
> <top>
> <foo x="1" y="2"/>
> <bar x="1" y="2"/>
> <cars>
> <automobile red="1"/>
> </cars>
> <houses>
> <close deck="true"/>
> </houses>
> </top>
>
>
> Ofcourse the <mapswithdata> wrapper and the <maps> node would not be part
of
> the output. Can this be done or must it be in another file? Any help or
> direction much appreciated.
>
> "Daniel" <softwareengineer98037@y...> wrote in message
> news:OYFQZAtlEHA.3520@t......
> > Thanks, you are the xsl master.
> >
> > "Marrow" <m--a-r-r-o-w@m-a-r-r-o-w--s-o-f-t.com> wrote in message
> > news:eBLyAXglEHA.3104@T......
> > > Hi Daniel,
> > >
> > > > Is there any way to make it so that the attributes are not persisted
> if
> > > they
> > > > have no entry in the maps.xml?
> > >
> > > Yes, just replace this part of the stylesheet...
> > >
> > > <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>
> > >
> > > with...
> > >
> > > <xsl:if test="$this-attribute-map">
> > > <xsl:attribute name="{$this-attribute-map/@target}">
> > > <xsl:value-of select="."/>
> > > </xsl:attribute>
> > > </xsl:if>
> > >
> > >
> > > Cheers
> > > Marrow
> > > http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
> > > http://www.topxml.com/Xselerator
> > >
> > >
> > > "Daniel" <softwareengineer98037@y...> wrote in message
> > > news:uLZNdlelEHA.3816@T......
> > > > Is there any way to make it so that the attributes are not persisted
> if
> > > they
> > > > have no entry in the maps.xml?
> > > >
> > > > That worked accept the result it returned was:
> > > >
> > > > <?xml version="1.0" encoding="utf-8"?>
> > > > <top>
> > > > <foo x="1" y="2"/>
> > > > <bar x="1" y="2"/>
> > > > <cars>
> > > > <automobile red="1"/>
> > > > </cars>
> > > > <houses>
> > > > <close deck="true" frontdoor="open"/>
> > > > </houses>
> > > > </top>
> > > >
> > > > but the expected result was:
> > > >
> > > > <top>
> > > > <foo x="1" y="2"/>
> > > > <bar x="1" y="2"/>
> > > > <cars>
> > > > <automobile red="1"/>
> > > > </cars>
> > > > <houses>
> > > > <close deck="true"/>
> > > > </houses>
> > > > </top>
> > > >
> > > > For my case I do not want frontdoor="open" to be persisted because
it
> > has
> > > > no entry in the 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>
> > > >
> > > > Everything else looks perfect.
> > > >
> > > > "Marrow" <m--a-r-r-o-w@m-a-r-r-o-w--s-o-f-t.com> wrote in message
> > > > news:eMAl%23VakEHA.3912@T......
> > > > > 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 | |||
|
