Re: [xsl] Conditional Merge - what am I missing?

Subject: Re: [xsl] Conditional Merge - what am I missing?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 8 Jan 2002 08:08:21 +0000
Hi Nate,

> The results I'm getting are strange. The <RelatedParty> structures
> are being repeated twice for each of them. Also, if any element is
> not included in the data tree it is being excluded completely. If it
> isn't included in the stub it is being included anyways. This is the
> reverse of what I want, but looking at my XSLT it doesn't appear
> that the logic should be reversed. Can anyone shed some light on
> what I'm missing here?

There are a couple of things.

First, when you come across a particular element in your stub, you are
copying *all* the elements in the data with the same name. So when
your stub contains two RelatedParty elements and your data contains
two RelatedParty elements, you get both RelatedParty elements from the
data appearing for each RelatedParty elements in the stub (end up with
four of them).

I'm not sure what you want to do about that - it depends on what
semantics you have for the stub.

Second, the cause of missing information is that within your main
template, you apply templates without a select attribute at a point
where the current node is from the data portion of the document, not
the stub portion of the document:

  <xsl:for-each select="$context/child::*[name() = $currNodeName]">
    <xsl:copy>
      <xsl:apply-templates>
        <xsl:with-param name="context" select="current()"/>
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:for-each>

You need to have a variable to keep track of the current node at that
point, and to apply templates to its element children:

  <xsl:variable name="currNode" select="." />
  <xsl:for-each select="$context/child::*[name() = $currNodeName]">
    <xsl:copy>
      <xsl:apply-templates select="$currNode">
        <xsl:with-param name="context" select="current()"/>
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:for-each>

I hope that helps,

Jeni

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


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


Current Thread