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

Subject: RV: [xsl] Generally appending XML document to another one (using XSL)
From: Aitor San Juan <asanjuan@xxxxxxxxxxxxxx>
Date: Thu, 2 Oct 2003 16:14:46 +0200
Thanks, Americo. But I'd like my XSL style sheet to be as general as
possible, thus, not using any <template> to match any particular node.
You used a template for <book>. In my scenario, I have XML different
documents each of different structure, and what I'm trying is to
implement a general XSL to append. My example of a library was just
that, one kind of document. For other documents, I'd have to modify
the XSL. Do you understand me?

What I was trying to achieve in the following template was to find
the position of the root element and append its subtree of nodes
[ position() > $pos ]. I think the problem is in the template that
finds the position, but I'm not completely, and I can't find the
reason.

<xsl:template match="file">
	<xsl:variable name="f" select="document(string(.),/*)/node()"/>
	<xsl:variable name="pos">
		<xsl:call-template name="find-pos">
			<xsl:with-param name="nodes" select="$f"/>
			<xsl:with-param name="elementName"
                                  select="string(/append/@root)"/>
		</xsl:call-template>
	</xsl:variable>
	<xsl:copy-of select="$f[position()> $pos]"/>
</xsl:template>


<xsl:template name="find-pos">
	<xsl:param name="nodes"/>
	<xsl:param name="elementName"/>
	<xsl:choose>
		<xsl:when test="count($nodes)=0">
			<xsl:value-of select="'0'"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:choose>
				<xsl:when test="name($nodes[1]) =
$elementName">
					<xsl:value-of
select="number(count(preceding-sibling::node())+1)"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="find-pos">
						<xsl:with-param
name="nodes" select="$nodes[position() > 1]"/>
						<xsl:with-param
name="elementName" select="$elementName"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>


-----Mensaje original-----
De: Americo Albuquerque [mailto:melinor@xxxxxxxx]
Enviado el: jueves, 02 de octubre de 2003 1:21
Para: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Asunto: RE: [xsl] Generally appending XML document to another one (using
XSL)


Hi

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Aitor San Juan
> Sent: Wednesday, October 01, 2003 8:41 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Generally appending XML document to another 
> one (using XSL)
> 
> 
> Hello all!
> 
> 	I am trying to write an XSL as general as possible to 
> append documents at the end of others. You can see the XML 
> input file and the XSL I'm working on. The "root" attribute 
> of the <append> element is the name of the root element to be 
> kept in the output, and under which all the child elements 
> are appended. Let me explain myself with the following examples.
> 

Try this:

  <xsl:template match="append">
    <xsl:element name="{@root}">
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>
  <xsl:template match="file">
    <xsl:apply-templates select="document(.)"/>
  </xsl:template>
  <xsl:template match="book">
    <xsl:copy-of select="."/>
  </xsl:template>

Regards,
Americo Albuquerque


************ 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
information.
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
prohibited.
************************************************************************** 



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


Current Thread