1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

XSLTで平成と令和をソートする

Last updated at Posted at 2019-04-11

XML

<xml>
 <date>令和2年7月1日</date>
 <date>令和元年3月13日</date>
 <date>平成31年1月1日</date>
</xml>

XSLT

xsltは一文字ずつしか置換できない・・・

<xsl:sort select="substring-after(translate(translate(translate(
substring-before(./date,'年'),'和','3'),'元','1'),'令','成'),'成')" />

平成と比べるには令和に30足せばよいので、和の字を3にする⇒元の字を1にする。
年と成で切り取れればいいので、令を成に変更する。

令和2年 ⇒ 令32年 ⇒ 成32年
令和元年 ⇒ 令3元年 ⇒ 令31年 ⇒ 成31年
平成31年

年の前の文字、成の後の文字で切り取る。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?