- PR -

xmlの文書構造を変換するxsltについて

1
投稿者投稿内容
すみれ
会議室デビュー日: 2005/07/12
投稿数: 13
投稿日時: 2005-11-16 17:56
いつも大変お世話になっております。
xslt初心者のすみれです。

下記のようなxml文書内で、<fnote>要素とその子要素を<p>要素の外に移動させるxsltを書いています。そして、<p>要素の中に含まれている<emph><sup>要素にも処理をしたくて、いろいろやってみたのですが、方法がわからず結果を出せずにいます。
階層の深い、もとのxmlの構造を変更できたらやりやすくなるのですが、もとを変えずに変換する方法を覚えたいと思っています。
どうか、お力を貸していただきたく、書き込みました。
いつも質問の立場ばかりで、申し訳ありません。
何卒よろしくお願いいたします。

■xml文書
<h1>
<p>S2内容
<sup>
<emph type="red">1/</emph>
</sup>
<fnote>
<sup>
<emph type = "red">1/</emph>
</sup>
<emph type = "red">脚注</emph>
</fnote>内容
</p>
</h1>

■現状のxslt
<!--fnoteとその子要素を切り離す-->
<xsl:template match="h1/p">
<p>
<xsl:copy-of select="node( )[name( )!='fnote']"/>
</p>
<xsl:apply-templates select="fnote"/>
</xsl:template>

<!--fnoteの処理-->
<xsl:template match="fnote">
<p class="fnote">
<xsl:apply-templates/>
</p>
</xsl:template>

<!--supテンプレート-->
<xsl:template match="sup">
<xsl:element name="sup">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<!--emphテンプレート-->
<xsl:template match="emph">
<xsl:element name="span">
<xsl:attribute name="class">
<xsl:value-of select="@type"/>
</xsl:attribute>
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>

■現状の結果
<p>S2内容
<sup>
<emph type="red">1/</emph>
</sup>内容
</p>
<p class="fnote">
<sup>
<span class="red">1/</span>
</sup>
<span class="red">脚注</span>
</p>

■最終結果
<p>S2内容
<sup>
<span class="red">1/</span>
</sup>内容
</p>
<p class="fnote">
<sup>
<span class="red">1/</span>
</sup>
<span class="red">脚注</span>
</p>


[ メッセージ編集済み 編集者: すみれ 編集日時 2005-11-16 18:08 ]
未記入
常連さん
会議室デビュー日: 2005/07/04
投稿数: 31
投稿日時: 2005-11-17 09:31
×<xsl:copy-of select="node( )[name( )!='fnote']"/>
○<xsl:apply-templates select="node( )[name( )!='fnote']"/>
すみれ
会議室デビュー日: 2005/07/12
投稿数: 13
投稿日時: 2005-11-17 10:16
>未記入さん

ご返答ありがとうございます。
<xsl:apply-templates>要素、<xsl:copy-of>要素を理解しきれていなかったのですが、これでつかめてきたように思います。

ありがとうございました。


1

スキルアップ/キャリアアップ(JOB@IT)