この変換:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="bold[link]"><xsl:apply-templates/></xsl:template>
<xsl:template match="bold[link]/text()">
<bold><xsl:value-of select="."/></bold>
</xsl:template>
</xsl:stylesheet>
提供された XML ドキュメント(単一のトップ要素にラップされた提供されたフラグメント) に適用された場合:
<t>
<paragraph>
This is some text that is <bold>correct way</bold> <link>need
to be linked </link> to a document
</paragraph>
<paragraph>
This is some text that is <bold>incorrect <link>need
to be linked </link> way </bold> to a document
</paragraph>
</t>
必要な正しい結果が生成されます。
<t>
<paragraph>
This is some text that is <bold>correct way</bold>
<link>need
to be linked </link> to a document
</paragraph>
<paragraph>
This is some text that is <bold>incorrect </bold>
<link>need
to be linked </link>
<bold> way </bold> to a document
</paragraph>
</t>
OP は質問を更新しました。これは、最初の + 新しい要件を実装するわずかに変更された変換です。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="paragraph[bold]">
<paragraph>
<style name="bold"><xsl:apply-templates/></style>
</paragraph>
</xsl:template>
<xsl:template match="bold[link]"><xsl:apply-templates/></xsl:template>
<xsl:template match="bold[link]/text()">
<bold><xsl:value-of select="."/></bold>
</xsl:template>
</xsl:stylesheet>
この変換が次のドキュメントに適用された場合:
<t>
<paragraph>
This is some text that has no style
</paragraph>
<paragraph>
This is some text that is <bold>correct way</bold> <link>need
to be linked </link> to a document
</paragraph>
<paragraph>
This is some text that is <bold>incorrect <link>need
to be linked </link> way </bold> to a document
</paragraph>
</t>
必要な正しい結果が生成されます。
<t>
<paragraph>
This is some text that has no style
</paragraph>
<paragraph>
<style name="bold">
This is some text that is <bold>correct way</bold>
<link>need
to be linked </link> to a document
</style>
</paragraph>
<paragraph>
<style name="bold">
This is some text that is <bold>incorrect </bold>
<link>need
to be linked </link>
<bold> way </bold> to a document
</style>
</paragraph>
</t>