いくつかの XML ドキュメントをクリーンアップし、対応する ID のないすべての IDREF を削除しようとしています。なんらかの理由で、このばかげた問題を解決するための構文がわかりません。こんな事になると思っていたのに…
<xsl:template match="*">
<xsl:variable name="id_list" select="@id"/>
<xsl:if test="ref[not(contains($id_list, ./@rid))]">
<!-- do nothing -->
</xsl:if>
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
- ref は要素名で、@rid は refid です。
サンプル入力は次のようなものになります...
<?xml version="1.0" encoding="iso-8859-1"?>
<article>
<bdy>
<p>In the second category [<ref rid="bibtts2009060795101" type="bib">2</ref>] and third category [<ref rid="bibtts2009060795102" type="bib">3</ref>]</p>
</bdy>
<bib>
<bb pubtype="article" reftype="nonieee" id="bibtts2009060795101"><au sequence="first"><fnm>T.</fnm><snm>Smith</snm></au></bb>
</bib>
</article>
2 番目の参照<ref rid="bibtts2009060795102" type="bib">3</ref>
は削除されます