RE: Building a new tree

Subject: RE: Building a new tree
From: Bovone Stefano <Stefano.Bovone@xxxxxxxx>
Date: Wed, 14 Apr 1999 16:27:17 +0200
Title: RE: Building a new tree

This solution seems to work:

test.xml

<?xml version="1.0" ?>
 <document>
  <common id="D1">
   <tag>
    <p>First common part A</p>
    <p>First common part b</p>
   </tag>
  </common>
 <common id="D2">
  <tag>
   <title>SECOND COMMON PART</title>
  </tag>
 </common>
 <letter>
  <doc>
   <title>THE DOCUMENT</title>
   <p> generic <em>text</em> </p>
   <insert_common ref="D1" />
   <p>generic text</p>
    <insert_common ref="D2" />
    </doc>
  </letter>
</document>


test.xsl

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

<xsl:id attribute="id"/>

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


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


</xsl:stylesheet>

Current Thread