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

Conditional Merge - what am I missing?

Subject: Conditional Merge - what am I missing?
From: Nate Austin <naustin@xxxxxxxxxx>
Date: Mon, 7 Jan 2002 12:26:08 -0600
merging missing xml elements
Hello all.  I've got two bits of xml - one is a stub that basically defines
the layout (it has no text data in it), the other could have more or less
elements and contains text (I'll refer to that one as the data tree).  The
two will have a similar structure.  If the stub contains an element, then
all corresponding elements should be copied from the data tree.  The same
should be done for the sub-elements.  If there are no corresponding elements
in the data tree, the stub should be copied out itself.  Here's what I've
come up with:

<xsl:stylesheet version="1.0"
  <xsl:output encoding="utf-8" indent="yes" omit-xml-declaration="yes"/>

  <xsl:template match="MergeDataXML">
    <xsl:apply-templates select="DataStruct[@Id = 'Stub']"/>

  <xsl:template match="DataStruct">
      <xsl:attribute name="Id">
        <xsl:value-of select="//DataStruct[@Id != 'Stub']/@Id"/>
      <xsl:apply-templates select="*">
        <xsl:with-param name="context" select="//DataStruct[@Id !=

  <xsl:template match="*">
    <xsl:param name="context"/>
    <xsl:variable name="currNodeName" select="name()"/>
      <xsl:when test="count($context/child::*[name() = $currNodeName]) &gt;=
        <xsl:for-each select="$context/child::*[name() = $currNodeName]">
              <xsl:with-param name="context" select="current()"/>
        <xsl:copy-of select="."/>

  <DataStruct Id="Stub">
  <DataStruct Id="DataTree">
      <CustName>Some Name</CustName>
      <FedId>Some Id</FedId>

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?


Nate Austin
International Decision Systems

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

Current Thread


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.
First Name
Last Name
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.