[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Conditional Merge - what am I missing?

Subject: Re: Conditional Merge - what am I missing?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 8 Jan 2002 08:08:21 +0000
merge element in xslt
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.