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]

Combining XMLs



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.

I want to insert the values of A.XML <themes/> into my source XML were
applicable ( so x3 will be ignored).


I am trying two different ways without much success. The problem with my
first attempt seems to be that the structures of the XML are the same. So I
need to differentiate my AbbreviateAbsoluteLocationPath fo <le>. For now I
altered the incoming XML to be called <Tle>just to see if I could get it to
work. No luck

Any help would be appreciated.

SOURCE XML:

<laes>
    <le>
      <l_params>
        <l_name>x1</l_name>
        <l_level>1</l_level>
      </l_params>
      <themes/>
    </le>
    <le>
      <l_params>
        <layer_name>x3</layer_name>
        <layer_level>2</layer_level>
      </l_params>
      <themes>
        <o_theme>
           <theme_name>TO BE REPLACED</theme_name>
           <theme_level>1</theme_level>
        </o_theme>
      </themes>
    </le>
  </laes>

A.XML:

<laes>
    <Tle>
      <l_params>
        <l_name>x1</l_name>
        <level>1</level>
      </l_params>
      <themes>
        <o_theme>
           <theme_name>TEST </theme_name>
           <theme_level>1</theme_level>
        </o_theme>
      </themes>
    </Tle>
    <Tle>
      <l_params>
        <l_name>x2</l_name>
        <level>2</level>
      </l_params>
      <themes/>
    </Tle>
    <Tle>
      <l_params>
        <l_name>x3</l_name>
        <level>3</level>
      </l_params>
      <themes/>
    </Tle>
  </laes>

MY XSL:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl
="http://www.w3.org/1999/XSL/Transform";>
     <xsl:output method="xml" indent="no"/>
     <xsl:key name="key-lookup" match="l_params" use="l_name"/>
     <xsl:variable name="l-top" select="document('A.XML')"/>
     <xsl:template match="*|@">
          <xsl:copy>
               <xsl:copy-of select="@*"/>
               <xsl:apply-templates/>
          </xsl:copy>
     </xsl:template>

     <!--FIRST ATTEMPT
     <xsl:template match="themes">
          <xsl:element name="theme">
               <xsl:apply-templates select="$l-top">
                    <xsl:with-param name="curr-label" select="."/>
               </xsl:apply-templates>
          </xsl:element>
     </xsl:template>
     <xsl:template match="Tl">
          <xsl:param name="curr-label"/>
          <xsl:value-of select="key('key-lookup',
($curr-label/../l_params/l_name))"/>
     </xsl:template>

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

</xsl:stylesheet>


 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]