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]
Other format: [Raw text]

Re: foreign keys in a xml-database, how to copy a node and only one/some of its childs


Hi everybody,

 J.Pietschmann wrote:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> You probably need a composite key.
>    <xsl:key name="tool-version" match="tool"
>       use="concat(@name,'#',release/@name)"/>
>    <!-- convenience variable holding second.xml -->
>    <xsl:variable name="tool-def" >select="document('second.xml')"/>

>    <xsl:template match="project">
>     ...
>      <xsl:for-each select="tool">
>        <!-- build the key of the tool used -->
>        <xsl:variable name="key" >select="concat(@name,'#',@version)"/>
>        <!-- change context for key lookup -->
>        <xsl:for-each select="$tool-def">
>          <xsl:apply-templates >select="key('tool-version',$key)"/>
>        </xsl:for-each>
>        ...
>      </xsl:for-each>
>     </xsl:template>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++

First many thanks for your help again!!
I followed your instructions and defined the key plus the surrounding source-code:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 <xsl:variable name="sw-file" select="document('second.xml')"/>
 
  <xsl:key name="toolkey" match="tool" use="concat(@name,'#',release/@name)"/>

<xsl:template match="project" mode="sw">
   <xsl:variable name="tools">
     <xsl:for-each select="tool">
      
<!--.................. build the 'key' of the current tool ................-->

      <xsl:variable name="key" select="concat(@name,'#',@version)"/>

<!--.................... change context for key lookup ....................-->
      
      <xsl:for-each select="$sw-file">
       <xsl:copy-of select="key('toolkey',$key)"/>
      </xsl:for-each>
     </xsl:for-each>
    </xsl:variable>
  
<!--....................... get sorted tool-list ..........................-->
 
    <xsl:variable name="sw">
     <xsl:for-each select="exsl:node-set($tools/tool)">
      <xsl:sort data-type="text" lang="en" select="@category"/>
      <xsl:sort data-type="text" lang="en" select="@name"/>
      <xsl:copy-of select="."/>
     </xsl:for-each>
    </xsl:variable>
   ......
         <xsl:apply-templates select="exsl:node-set($sw)"/>
  ......
</xsl:template>
 
<xsl:template match="tool">
  ......
   <td>
    <xsl:value-of select="@name"/>
    <xsl:for-each select="child::release">   
     <xsl:text>&#160;</xsl:text>
     <xsl:value-of select="@name"/>
    </xsl:for-each>
   </td>
  ......
</xsl:template>

++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
The PROBLEM is, that the above construction copies each tool with all its childs ( releases ) from second.xml and not only those, whose @name fits @version of the corresponding tool from first xml. 

So I ask you amd each other expert joining this list:

Is there any possibility ( hopefully with ONE stylesheet ) to copy a node and only ONE/some of its childs ( those who fit a certain condition ) from a second xml-file???????

Help will be greatly appreciated!!!!!!

To remind you of the background I just post the 2 xml-files again!!!

========================================================
I have two xml-files, the first stores projects and references to needed
 tools, the second stores the details of these tools:

 first.xml:
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 <devEnviron name="Oscar">
   <project name="RR 30" version="A">
     <tool name="Gnu C Compiler" version="3.0.1">
       <location name="SDBH58"/>
     </tool>
     <tool name="Gnu Debugger" version="2.4.1">
       <location name="SDBWAW"/>
     </tool> 
      ....
   </project>
 ...
 </devEnviron>
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++

 second.xml:
 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
  <software>
    <tool name="Gnu C Compiler"
      company="open source" 
          category="Compiler-Interpreter"
          phase="Coding">

      <release name="3.0.1">
        <os name="Solaris" version="7" kernel="1.3.0"/>
        <computer name="SDBWAW" path="/bin/compiler">
          <docu kind="man" loc="/bin/docus">
            gcc
          </docu>
        </computer>
        <docu kind="url" loc="internet">
          www.gcc.com
        </docu>
      </release>
  
      <release name="3.1.1">
        <os name="Solaris" version="7" kernel="1.3.1"/>
        <computer name="SDBH58" path="/bin/compiler">
          <docu kind="man" loc="/bin/tools/docus">
            gcc
          </docu>
        </computer>
        <docu kind="url" loc="internet">
          www.gcc.com
        </docu>
      </release>
      .... 
   </tool>
  
    <tool name="Gnu Debugger"
      company="open source" 
          category="Debugger" 
          phase="Coding">
    
      <release name="2.4.1">
        <os name="Solaris" version="7" kernel="1.3.0"/>
        <computer name="SDBWAW" path="/bin/debugger">
          <docu kind="man" loc="/bin/docus">
            gdb
          </docu>
        </computer>
        <docu kind="url" loc="internet">
          www.gdb.com
        </docu>
      </release>      
      ..... 
   </tool>
     ....
  </software>
 ++++++++++++++++++++++++++++++++++++++++++++++++++++++

=======================================================

I hope somebody has implemented something simillar and can give me a fast advice, cause time is ticking!!!!!

Many Thanks,

Stefan Greim

 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]