Here is a sample stylesheet:
Code:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="k1" match="sam" use="generate-id(preceding-sibling::sect3[1])"/>
<xsl:template match="book">
<xsl:copy>
<xsl:apply-templates select="sect3"/>
</xsl:copy>
</xsl:template>
<xsl:template match="sect3">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
<xsl:apply-templates select="key('k1', generate-id())"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
When applied against the following XML input sample
Code:
<book>
<sect3 id="a397038pkin" temp="ch0001s0219">
<title>Pharmacokinetics</title>
<para>For further information on pharmacology of antihistamines, <link linkend="a382920pcol">see the Antihistamines General Statement 4:00</link>.</para></sect3>
<sam>See <link linkend="a382920pkin">Pharmacokinetics in the associated General Statement for more information.</link></sam>
<sam>See <link linkend="a382920chem-stab">Chemistry and Stability in the associated General Statement for more information.</link></sam>
<sam>See <link linkend="a382929uses">Uses in the associated General Statement for more information.</link></sam>
<sect3 id="s2" temp="ch0001s0219">
<title>foo</title>
<para>For further information on pharmacology of antihistamines, <link linkend="a382920pcol">see the Antihistamines General Statement 4:00</link>.</para></sect3>
<sam>See <link linkend="a382920pkin">Pharmacokinetics in the associated General Statement for more information.</link></sam>
<sam>See <link linkend="a382920chem-stab">Chemistry and Stability in the associated General Statement for more information.</link></sam>
<sam>See <link linkend="a382929uses">Uses in the associated General Statement for more information.</link></sam>
</book>
it outputs
Code:
<?xml version="1.0" encoding="utf-8"?>
<book>
<sect3 id="a397038pkin" temp="ch0001s0219">
<title>Pharmacokinetics</title>
<para>For further information on pharmacology of antihistamines, <link linkend="a382920pcol">see the Antihistamines General Statement 4:00</link>.</para>
<sam>See <link linkend="a382920pkin">Pharmacokinetics in the associated General Statement for more information.</link>
</sam>
<sam>See <link linkend="a382920chem-stab">Chemistry and Stability in the associated General Statement for more information.</link>
</sam>
<sam>See <link linkend="a382929uses">Uses in the associated General Statement for more information.</link>
</sam>
</sect3>
<sect3 id="s2" temp="ch0001s0219">
<title>foo</title>
<para>For further information on pharmacology of antihistamines, <link linkend="a382920pcol">see the Antihistamines General Statement 4:00</link>.</para>
<sam>See <link linkend="a382920pkin">Pharmacokinetics in the associated General Statement for more information.</link>
</sam>
<sam>See <link linkend="a382920chem-stab">Chemistry and Stability in the associated General Statement for more information.</link>
</sam>
<sam>See <link linkend="a382929uses">Uses in the associated General Statement for more information.</link>
</sam>
</sect3>
</book>
If that does not help then you need to provide more details on the possible input and the result you want to create.