Here is an adapted stylesheet:
Code:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="doc/docid">
<xsl:copy>
<xsl:number count="doc"/>
</xsl:copy>
</xsl:template>
<xsl:template match="REF">
<xsl:copy>
<xsl:apply-templates select="@* | L_TO_C"/>
<xsl:if test="not(doc2c)">
<xsl:apply-templates select="/Tremble/Dakota/doc" mode="m1"/>
</xsl:if>
<xsl:apply-templates select="r2p"/>
</xsl:copy>
</xsl:template>
<xsl:template match="doc" mode="m1">
<doc2c>
<xsl:apply-templates select="docid" mode="m1"/>
<xsl:apply-templates select="/Tremble/Dakota/C/CID"/>
</doc2c>
</xsl:template>
<xsl:template match="doc/docid" mode="m1">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>