Building a new tree

Subject: Building a new tree
From: Bovone Stefano <Stefano.Bovone@xxxxxxxx>
Date: Tue, 13 Apr 1999 16:01:21 +0200
Title: Building a new tree

I have, for example, the following XML document:

<?xml version="1.0"?>

<document>
        <common id="D1">
          <p>First common part A</p>
          <p>First common part b</p>
            </common>

        <common id="D2">
          <title>SECOND COMMON PART</title>
        </common>

        <letter>
          <doc>
          <title> THE DOCUMENT </TITLE>
          <p> generic text</p>
          <insert_common ref="D1"/>
          <p> generic text</p>
          <insert_common ref="D2"/>
              </doc>
             </letter>
</document>

and I want using a XSL document to have:

<?xml version="1.0"?>
  <doc>
          <title> THE DOCUMENT </TITLE>
          <p> generic text</p>
          <p>First common part A</p>
          <p>First common part b</p>
          <p> generic text</p>
          <title>SECOND COMMON PART</title>
   </doc>
            
I thought to use:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http:/www.w3.org/TR/WD-xsl">

<xsl:template match="/">
 <xsl:template select=".//letter"/>
</xsl:template>

<xsl:template match="letter">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="letter/* | letter//*">
 <xsl:copy>
  <xsl:apply-templates select="text() | @* | * | ./* | insert_common"/>
 </xsl:copy>
</xsl:template>

<xsl:template match="insert_common">
  <xsl:apply-templates select="id(@ref)/tag"/>
</xsl:template>

<xsl:template match="tag/*">
 <xsl:copy>
  <xsl:apply-templates select="text() | * | ./*"/>
 </xsl:copy>
</xsl:template>

</xsl:stylesheet>      


but it doesn't work.

Have anybody any idea ?

Thanks. Bye.

Current Thread