ID ルールの単純なオーバーライドのみを使用します。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="linkCode">
<a href="file-{@code1}-{@code2}-{@code3}.html">this link</a>
</xsl:template>
<xsl:template match="parag">
<p><xsl:apply-templates select="node()|@*"/></p>
</xsl:template>
</xsl:stylesheet>
この変換が次の XML ドキュメントに適用されると(提供されたフラグメントが 1 つの最上位要素にラップされ、整形式の XML ドキュメントが取得されます):
<t>
<parag>blah blah blah</parag>
<parag>blah blah, refer to <linkCode code1="a" code2="b" code3="c"/> for further details.</parag>
</t>
必要な正しい結果が生成されます。
<t>
<p>blah blah blah</p>
<p>blah blah, refer to <a href="file-a-b-c.html">this link</a> for further details.</p>
</t>
そして、一番上の要素を出力しないようにしたい場合:
このテンプレートを追加するだけです:
<xsl:template match="/*"><xsl:apply-templates/></xsl:template>
したがって、完全なコードは次のようになります。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" />
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="linkCode">
<a href="file-{@code1}-{@code2}-{@code3}.html">this link</a>
</xsl:template>
<xsl:template match="parag">
<p><xsl:apply-templates select="node()|@*"/></p>
</xsl:template>
<xsl:template match="/*"><xsl:apply-templates/></xsl:template>
</xsl:stylesheet>