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

Re:XML Merge

Subject: Re:XML Merge
From: David Carver <d_a_carver@xxxxxxxxx>
Date: Fri, 27 Jun 2003 06:17:19 -0700 (PDT)
xml merge
>From: David Carlisle <davidc@xxxxxxxxx>
>Subject: Re:  Re: XSL-List Digest V4 #1421

>I've changed that to the following now:
><xsl:when test="action">
>    <xsl:apply-templates select="action"/>
></xsl:when>
>
>
>unless you also moved the xsl:copy outside that is still going to give
>you the problem that parents of action elements are not copied.
>I don'tthink you want the xsl:choose at all.

Since that last post, I've made some slight modifications, and I'm
closer to what I'm trying to accomplish.  All parents are being copied
as far as I can tell (at least they appear to be when I'm stepping
through the transformation with XML Spy 5's debugger).

Here is the latest style sheet:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
   <xsl:template match="/">
      <xsl:apply-templates />
   </xsl:template>
   
   <xsl:template 
     match="*|@*|comment()|processing-instruction()|text()">
       <xsl:choose>
          <xsl:when test="action-mappings/action">
             <xsl:apply-templates select="action-mappings/action"/>
          </xsl:when>
       <xsl:otherwise>
        <xsl:copy>
         <xsl:apply-templates
          select="*|@*|comment()|processing-instruction()|text()"/>
         </xsl:copy>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:template>
   
   <xsl:template match="action-mappings/action">
      <xsl:choose>
      <xsl:when test="@path =
document('struts-config_new_variables01.xml')//action/@path">
      <!-- Copy the value where @path = document()//action/@path -->
           <xsl:variable name="pathvalue" select="@path"/>
           <xsl:variable name="nodeset"
select="document('struts-config_new_variables01.xml')//action[@path =
$pathvalue]"/>
<!--          <xsl:copy-of
select="document('struts-config_new_variables01.xml')//action[@path =
$pathvalue]"/> -->
         <xsl:element name="action">
             <xsl:apply-templates select="$nodeset/@*"/>
             <xsl:apply-templates select="$nodeset/forward"/>
             <xsl:apply-templates select="* | @* | comment() |
processing-instruction() | text()"/>
         </xsl:element>
      </xsl:when>
      <xsl:otherwise>
         <xsl:copy>
             <xsl:apply-templates
          select="*|@*|comment()|processing-instruction()|text()"/>
         </xsl:copy>

      </xsl:otherwise>
      </xsl:choose>
   </xsl:template>
   
 <xsl:template match="action/forward">
     <xsl:copy>
         <xsl:apply-templates
          select="*|@*|comment()|processing-instruction()|text()"/>
    </xsl:copy>
   </xsl:template>
</xsl:stylesheet>

The only problem I'm running into and need to fix is that if an action
element has two child forward elements in the external xml file, and
the  action element in the main xml file has the same two child
elements, both the forward elements and all the forward elements from
the main xml file are being copied.   i.e. if I have something like
this:

external xml file:
<action>
    <forward path="1" step="0"/>
    <forward path="2" step="2"/>
</action>

main xml file:
<action>
    <forward path="1" step="1"/>
    <forward path="2" step="2"/>
    <forward path="3" step="2"/>
</action>

result file:
<action>
    <forward path="1" step="0"/>
    <forward path="2" step="2"/>
    <forward path="1" step="1"/>
    <forward path="2" step="2"/>
    <forward path="3" step="2"/>
</action>

What I want is the following output:
<action>
    <forward path="1" step="0"/>
    <forward path="2" step="2"/>
    <forward path="3" step="2"/>
</action>



=====
"The difference between fiction and reality is that fiction has to make
sense." - Tom Clancy

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


Current Thread
  • Re:XML Merge
    • David Carver - Fri, 27 Jun 2003 09:17:58 -0400 (EDT) <=

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.