This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Combining XMLs


Hi Kevin,

> I am attempting to combine elements of one XML into another. I want
> to basically cut and paste one portion of an XML file into another
> XML file with the same basic structure. However, they do not have
> the exact same elements. Document A may or may not contain the
> elements of Document B. For instance, in my example below. My source
> XML contains <l_name/> X1 and X2 while my A.XML file contains these
> but also contains X3.

The problem with your first attempt is that you're losing the
parameter because you're passing it to the template that handles the
root node of A.xml but don't have such a template to accept the
parameter. Parameters don't get passed along by the built-in
templates.

What you want is more like:

<xsl:template match="themes">
  <themes>
    <!-- copy the existing themes -->
    <xsl:copy-of select="o_theme" />
    <!-- apply templates to get the themes from A.xml -->
    <xsl:apply-templates select="$l-top" mode="copyThemes">
      <xsl:with-param name="curr-label" select="." />
    </xsl:apply-templates>
  </themes>
</xsl:template>

<xsl:template match="/" mode="copyThemes">
  <xsl:param name="curr-label" />
  <xsl:copy-of select="key('key-lookup',
                           $curr-label/../l_params/l_name)
                         /themes/o_theme" />
</xsl:template>

The second attempt is also close; the only thing is that you're not
thinking about the identity of the current node when you construct
your paths. Your source and A.xml XML looks like:

  laes
   +- le
      +- l_params
      |  +- l_name
      |  +- l_level
      +- themes
         +- o_theme
            +- theme_name
            +- theme_level

Now look at your template:

>       <xsl:template match="themes">
>           <xsl:element name="themes">
>             <xsl:copy-of select="$l-top//themes[l_name = current
()/l_name]"/>>
>           </xsl:element>
>      </xsl:template>

You're trying to find a themes element whose l_name child is the same
as the l_name child of the current (themes) element. The themes
elements don't have l_name children; what you want is more like:

<xsl:template match="themes">
  <themes>
    <xsl:copy-of select="$l-top/laes/Tle[l_params/l_name =
                                         current()/../l_params/l_name]
                           /themes/o_theme" />
  </themes>
</xsl:template>

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]