Search Posts

Visits: 644

[2022-12-29] JP PINT Version 1.0対応でcbc:CustomizationIDの値がurn:fdc:peppol:jp:billing:3.0 に変更されました。本記事のスタイルシートでは、cbc:CustomizationIDの値のチェックを外しています。
[2022-01-05] 作成

概要

XML文書をスタイルシートでHTML文書に変換して表示します。
JavaでXSLT2をサポートしているライブラリ、SaxonをSourceforgeから取得して利用します。
スタイルシートは、specification identifier (IBT-24) の値に基づいて、適用可否を判定しています。
日本版のv0.9では、次の値が指定されています。
urn:peppol:pint:billing-3.0@jp:peppol-1

Javaの変換ライブラリSaxonの取得方法は、ページの最後に記述しました。

欧州規格の電子インボイスの例

先日記載した欧州規格電子インボイスのスキーマトロン検証環境にあるように、スキーマトロンの検証環境には、電子インボイスの例とともにXSLTスタイルシートも提供されています。

├── ubl
│   ├── examples
│   │   ├── ubl-tc434-creditnote1.xml
│   │   ├── ubl-tc434-example1.xml
│   │   ├── ubl-tc434-example2.xml
│   │   ├── ubl-tc434-example3.xml
│   │   ├── ubl-tc434-example4.xml
│   │   ├── ubl-tc434-example5.xml
│   │   ├── ubl-tc434-example6.xml
│   │   ├── ubl-tc434-example7.xml
│   │   ├── ubl-tc434-example8.xml
│   │   └── ubl-tc434-example9.xml

ここでは、日本版のv0.9で公開されているいたダウンロードファイルに含まれているスタイルシートのcbc:CustomizationIDの値をurn:peppol:pint:billing-3.0@jp:peppol-1のチェックを外したものを用いて、XSLT変換したページを次の表から確認できます。

XMLファイル XSLT変換後のHTML
ubl-tc434-example1.xml example1.html
ubl-tc434-example2.xml example2.html
ubl-tc434-example3.xml example3.html
ubl-tc434-example4.xml example4.html
ubl-tc434-example5.xml example5.html
ubl-tc434-example6.xml example6.html
ubl-tc434-example7.xml example7.html
ubl-tc434-example8.xml example8.html
ubl-tc434-example1.xml example1.html
ubl-tc434-example9.xml example9.html

変換は、次のコマンドで実行しました。

java -jar saxon-he-10.6.jar -o:example1.html ubl-tc434-example1.xml stylesheet-ubl.xslt
java -jar saxon-he-10.6.jar -o:example2.html ubl-tc434-example2.xml stylesheet-ubl.xslt
java -jar saxon-he-10.6.jar -o:example3.html ubl-tc434-example3.xml stylesheet-ubl.xslt
java -jar saxon-he-10.6.jar -o:example4.html ubl-tc434-example4.xml stylesheet-ubl.xslt
java -jar saxon-he-10.6.jar -o:example5.html ubl-tc434-example5.xml stylesheet-ubl.xslt
java -jar saxon-he-10.6.jar -o:example6.html ubl-tc434-example6.xml stylesheet-ubl.xslt
java -jar saxon-he-10.6.jar -o:example7.html ubl-tc434-example7.xml stylesheet-ubl.xslt
java -jar saxon-he-10.6.jar -o:example8.html ubl-tc434-example8.xml stylesheet-ubl.xslt
java -jar saxon-he-10.6.jar -o:example9.html ubl-tc434-example9.xml stylesheet-ubl.xslt

stylesheet-ubl.xsltは、こちらからダウンロードしてください。 日本版のv0.9の配布ファイルを若干修正しています。

Javaの変換ライブラリSaxon

Stackoverflowに紹介されている saxon9he.jar の使用例を参考にしました。次のようにjavaコマンドでライブラリに引数を指定してXSLT変換します。

java -jar saxon9he.jar -o:outputfile.xml data.xml transform.xslt

例では、saxon9he.jar を使用していますが、Getting started with Saxon on the Java platformでは、Sourceforgeからダウンロードするように指定されていました。

sourceforge.netで確認すると、SaxonHE10-6Jが最新のようでしたので、これを使用します。

サーバー上で、wgetコマンドでzipファイルを取得して解凍しました。

wget https://sourceforge.net/projects/saxon/files/Saxon-HE/10/Java/SaxonHE10-6J.zip

$ wget https://sourceforge.net/projects/saxon/files/Saxon-HE/10/Java/SaxonHE10-6J.zip
--2022-01-05 08:57:24--  https://sourceforge.net/projects/saxon/files/Saxon-HE/10/Java/SaxonHE10-6J.zip
sourceforge.net (sourceforge.net) をDNSに問いあわせています... 204.68.111.105
sourceforge.net (sourceforge.net)|204.68.111.105|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 301 Moved Permanently
場所: https://sourceforge.net/projects/saxon/files/Saxon-HE/10/Java/SaxonHE10-6J.zip/ [続く]
--2022-01-05 08:57:25--  https://sourceforge.net/projects/saxon/files/Saxon-HE/10/Java/SaxonHE10-6J.zip/
sourceforge.net:443 への接続を再利用します。
HTTP による接続要求を送信しました、応答を待っています... 302 Found
場所: https://sourceforge.net/projects/saxon/files/Saxon-HE/10/Java/SaxonHE10-6J.zip/download [続く]
--2022-01-05 08:57:25--  https://sourceforge.net/projects/saxon/files/Saxon-HE/10/Java/SaxonHE10-6J.zip/download
sourceforge.net:443 への接続を再利用します。
HTTP による接続要求を送信しました、応答を待っています... 302 Found
場所: https://downloads.sourceforge.net/project/saxon/Saxon-HE/10/Java/SaxonHE10-6J.zip?ts=gAAAAABh1N7lDNyJ6g6CrMSA4QXIunKjoJZ_bxC6vZa_n7vpVTBTyFjNnpBLPtcFCul7EwQtrgebnQg0oUgIiZSDshBBOgA1XA%3D%3D&use_mirror=jaist&r= [続く]
--2022-01-05 08:57:25--  https://downloads.sourceforge.net/project/saxon/Saxon-HE/10/Java/SaxonHE10-6J.zip?ts=gAAAAABh1N7lDNyJ6g6CrMSA4QXIunKjoJZ_bxC6vZa_n7vpVTBTyFjNnpBLPtcFCul7EwQtrgebnQg0oUgIiZSDshBBOgA1XA%3D%3D&use_mirror=jaist&r=
downloads.sourceforge.net (downloads.sourceforge.net) をDNSに問いあわせています... 204.68.111.105
downloads.sourceforge.net (downloads.sourceforge.net)|204.68.111.105|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 302 Found
場所: https://jaist.dl.sourceforge.net/project/saxon/Saxon-HE/10/Java/SaxonHE10-6J.zip [続く]
--2022-01-05 08:57:25--  https://jaist.dl.sourceforge.net/project/saxon/Saxon-HE/10/Java/SaxonHE10-6J.zip
jaist.dl.sourceforge.net (jaist.dl.sourceforge.net) をDNSに問いあわせています... 150.65.7.130, 2001:df0:2ed:feed::feed
jaist.dl.sourceforge.net (jaist.dl.sourceforge.net)|150.65.7.130|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 5866254 (5.6M) [application/octet-stream]
`SaxonHE10-6J.zip' に保存中

SaxonHE10-6J.zip                   100%[===============================================================>]   5.59M  10.3MB/s    in 0.5s

2022-01-05 08:57:26 (10.3 MB/s) - `SaxonHE10-6J.zip' へ保存完了 [5866254/5866254]

$ ls
SaxonHE10-6J.zip

$ unzip SaxonHE10-6J.zip
Archive:  SaxonHE10-6J.zip
  inflating: saxon-he-10.6.jar
  inflating: jline-2.14.6.jar