倭マン's BLOG

くだらない日々の日記書いてます。 たまにプログラミング関連の記事書いてます。 書いてます。

単純化(20) : 要素

単純化の第20段階は、<notAllowed> 要素の処理です。

  • 対象ノードの箇所では接頭辞 "rng" は「RELAX NG 名前空間」に関連づけられているとします。
  • サンプルでは見やすさのために空白や改行を入れているところがありますが、実際には単純化の第2段階で除去されています。

このステップでは、以下で説明する4つの操作を、どれも行えなくなるまで繰り返し適用します。

<notAllowed> 要素を子要素にもつ <attribute>, <list>, <group>, <interleave>, <oneOrMore> 要素

対象ノード
//*[self::rng:attribute or self::rng:list or self::rng:group or self::rng:interleave or self::rng:oneOrMore][rng:notAllowed]
操作
<notAllowed> 要素に変える。

サンプル

<group>
  <notAllowed/>
  <empty/>
</group>

<notAllowed/>

2つの <notAllowed> 要素を子要素にもつ <choice> 要素

対象ノード
//rng:choice[count(rng:notAllowed) = 2]
操作
<notAllowed> 要素に変える。

サンプル

<choice>
  <notAllowed/>
  <notAllowed/>
</choice>

<notAllowed/>

1つの <notAllowed> 要素を子要素にもつ <choice> 要素

対象ノード
//rng:choice[count(rng:notAllowed) = 1]
操作
<notAllowed> 要素でない子要素に置き換える

サンプル

<choice>
  <notAllowed/>
  <empty/>
</choice>

<empty/>

<notAllowed> 要素を子要素にもつ <except> 要素

対象ノード
//rng:except[rng:notAllowed]
操作
除去する

サンプル

<anyName>
  <except><notAllowed/></except>
</anyName>

<anyName/>

事後条件

  • <notAllowed> 要素が <start> 要素もしくは <element> 要素の子要素としてのみ現れる。