内部の値が今年、昨年、または来年のいずれかであることをテストする Schematron ルールを作成したいと考えています。
問題は、値に 2013 ~ 2014 などの年の範囲が含まれる可能性があることです。(2013) のテキスト ノードの最初の 4 桁のみをテストしたい。
これは私が書いたものですが、正しくありません。テキスト ノードの位置を返すことはできますか?
XML ファイル:
<article>
<front>
<article-meta>
<pub-date pub-type="epub-ppub">
<year>2013-2014</year>
</pub-date>
</article-meta>
</front></article>
スキーマトロンのルール:
<pattern abstract="false" id="year">
<rule context="/article/front/article-meta">
<assert
test="number(pub-date[@pub-type='epub-ppub']/year/text()[position() = 4]) = year-from-date(current-date()) or number(pub-date/year) = (year-from-date(current-date()) + 1) or number(pub-date/year) = (year-from-date(current-date()) - 1) or number(pub-date/year) = (year-from-date(current-date()) - 2)"
>The publication year (pub-date[@pub-type='epub-ppub']/year) is "<value-of
select="pub-date[@pub-type='epub-ppub']/year"/>". It should be the current year
(<value-of select="year-from-date(current-date())"/>), last year, or next
year.</assert>
</rule>
</pattern>
XML ファイルを検証すると、ルールが発生しますが、2013 年が有効な年です: 発行年 (pub-date[@pub-type='epub-ppub']/year) は "2013-2014" です。今年 (2013 年)、昨年、または来年である必要があります。