RE: [xsl] Generally appending XML document to another one (using XSL) (SOLVED)

Subject: RE: [xsl] Generally appending XML document to another one (using XSL) (SOLVED)
From: Aitor San Juan <asanjuan@xxxxxxxxxxxxxx>
Date: Mon, 6 Oct 2003 08:56:52 +0200
Hello all! I think I came to a solution of what I was trying to.
What I wanted was to develop an XSL to append the content of one
XML document to another. I also wanted the XSL to be as general as
possible, so that I could use the XSL for any kind of XML document.

I don't know whether it is efficient or not. At least it does what
I was after. It might not be so efficient with large documents to

Now, the input XML document to my XSL is of the form:

<append root="a_qname">
    <file>URI to file</file>
    <file>URI to file</file>

The value of the "root" attribute is the name of the root element
to be kept in the output, so any element with that name (which
should be the root element name of the documents to append) will
be ignored in the result.


input XML document:
<append root="library">

Note: file2.xml could have also a root element <library>; this
      would be ignored.

file1.xml                      file2.xml
=========                      =========
<library>                      <book isbn="77">
   <book isbn="1">                <author>A77</author>
      <author>A1</author>         <title>T77</title>
      <title>T1</title>        </book>
   <book isbn="2">

   <book isbn="1">
   <book isbn="2">
   <book isbn="77">


<?xml version="1.0"?>

<xsl:stylesheet version="1.0"

   <xsl:output encoding="ISO-8859-1"
                method="xml" indent="yes" version="1.0"/>

   <xsl:template match="append">
      <xsl:element name="{@root}">

   <xsl:template match="file">
      <xsl:call-template name="copier">
         <xsl:with-param name="nodes"
         <xsl:with-param name="elementName"

   <xsl:template name="copier">
      <xsl:param name="nodes"/>
      <xsl:param name="elementName"/>
         <xsl:when test="count($nodes)=0">
            <xsl:value-of select="$nodes"/>
         <xsl:when test="count($nodes)=1 and (name($nodes[1]) !=
            <xsl:copy-of select="$nodes"/>
         <xsl:when test="name($nodes[1]) = $elementName">
            <xsl:copy-of select="$nodes/*"/>
            <xsl:call-template name="copier">
               <xsl:with-param name="nodes"
                               select="$nodes[position() > 1]"/>
               <xsl:with-param name="elementName"


************ LEGEZKO OHARRA / AVISO LEGAL / LEGAL ADVICE *************
Mezu honek isilpeko informazioa gorde dezake, edo jabea duena, edota legez
babestuta dagoena.
Zuri zuzendua ez bada, bidali duenari esan eta ezabatu, inori berbidali
edo gorde gabe,legeak debekatzen duelako mezuak erabiltzea baimenik gabe.
Este mensaje puede contener información confidencial, en propiedad o
legalmente protegida.
Si usted no es el destinatario, le rogamos lo comunique al remitente
y proceda a borrarlo, sin reenviarlo ni conservarlo, ya que su uso no 
autorizado está prohibido legalmente.
This message may contain confidential, proprietary or legally privileged
If you are not the intended recipient of this message, please notify it to
the sender and delete without resending or backing it, as it is legally

 XSL-List info and archive:

Current Thread