{"id":11996,"date":"2020-09-08T16:29:39","date_gmt":"2020-09-08T07:29:39","guid":{"rendered":"https:\/\/blog.antenna.co.jp\/ILSoft2\/?p=11996"},"modified":"2020-09-08T16:29:39","modified_gmt":"2020-09-08T07:29:39","slug":"xslt-3-0%ef%bc%88xpath-3-1%ef%bc%89json%e3%82%92xml%e3%81%ab%e5%a4%89%e6%8f%9b%e3%81%9b%e3%81%9a%e3%81%ab%e5%88%a9%e7%94%a8%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/blog.antenna.co.jp\/ILSoft2\/archives\/11996\/","title":{"rendered":"XSLT 3.0\uff08XPath 3.1\uff09JSON\u3092XML\u306b\u5909\u63db\u305b\u305a\u306b\u5229\u7528\u3059\u308b"},"content":{"rendered":"<p>\u5148\u9031\u306fXML\u306e\u5f62\u306b\u3057\u305fJSON\u3092\u3001XML\u306b\u3057\u306a\u3044\u307e\u307e\u6271\u3046\u65b9\u6cd5\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002CSL\u306f\u3067\u3066\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>XPath 3.1<sup>*1<\/sup>\u3067\u540d\u524d\u306bJSON\u304c\u5165\u308b\u95a2\u6570\u306f4\u3064\u3067\u3059\u3002<\/p>\n<ul>\n<li><code>fn:parse-json($json-text as xs:string?, $options as map(*))<\/code><\/li>\n<li><code>fn:json-doc($href as xs:string?, $options as map(*))<\/code><\/li>\n<li><code>fn:json-to-xml($json-text as xs:string?, $options as map(*))<\/code><\/li>\n<li><code>fn:xml-to-json($input as node()?, $options as map(*))<\/code><\/li>\n<\/ul>\n<p><var>$options<\/var>\u306b\u3064\u3044\u3066\u306f\u8aac\u660e\u3057\u307e\u305b\u3093\u3002JSON\u3092\u30c6\u30ad\u30b9\u30c8\u3068\u3057\u3066\u5f15\u6570\u306b\u3068\u308b\u306e\u304c<code>fn:parse-json()<\/code>\u3068<code>fn:json-to-xml()<\/code>\u3001<br \/>\n<code>fn:json-doc()<\/code>\u306f\u5916\u90e8JSON\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u3068\u304d\u306a\u3069\u306b\u6307\u5b9a\u3057\u307e\u3059\u3002<code>fn:unparsed-text()<\/code>\u3067\u53d6\u5f97\u3057\u305f\u30c6\u30ad\u30b9\u30c8\u3092<code>fn:parse-json()<\/code>\u3078\u9069\u7528\u3059\u308b\u306e\u3068<br \/>\n\u5927\u4f53\u540c\u3058\u3053\u3068\u3092\u884c\u3044\u307e\u3059\u3002\u4eca\u56de\u53d6\u308a\u4e0a\u3052\u308b\u306e\u306f<code>fn:parse-json()<\/code>\u3068<code>fn:json-doc()<\/code>\u306b\u3064\u3044\u3066\u3067\u3059\u3002<\/p>\n<h2>map\u3068array<\/h2>\n<p>\u95a2\u4fc2\u3059\u308b\u540d\u524d\u7a7a\u9593\u306f\u6b21\u306b\u6319\u3052\u308b\u3082\u306e\u3067\u3059\u3002<\/p>\n<ul>\n<li>fn=&#8221;http:\/\/www.w3.org\/2005\/xpath-functions&#8221;<\/li>\n<li>map=&#8221;http:\/\/www.w3.org\/2005\/xpath-functions\/map&#8221;<\/li>\n<li>array=&#8221;http:\/\/www.w3.org\/2005\/xpath-functions\/array&#8221;<\/li>\n<\/ul>\n<p>XPath 3.1\u306emap\u69cb\u9020\u3068array\u69cb\u9020\u306f\u4e00\u822c\u7684\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306b\u304a\u3051\u308b\u305d\u308c\u3068\u307b\u307c\u540c\u3058\u3082\u306e\u3067\u3001JSON\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u305d\u306e\u307e\u307e\u306e\u5f62\u3067\u683c\u7d0d\u3067\u304d\u307e\u3059\u3002<br \/>\n\u5148\u9031\u767b\u5834\u3057\u305fJSON\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><code>{\n    \"items\": [\n        {\n            \"id\": \"7646893\/2E3MJB9A\",\n            \"type\": \"book\",\n            \"title\": \"\u30b9\u30bf\u30a4\u30eb\u30b7\u30fc\u30c8\u958b\u767a\u306e\u57fa\u790e\",\n            \"publisher\": \"\u30a2\u30f3\u30c6\u30ca\u30cf\u30a6\u30b9\u682a\u5f0f\u4f1a\u793e\",\n            \"publisher-place\": \"Tokyo\",\n            \"event-place\": \"Tokyo\",\n            \"ISBN\": \"978-4-900552-23-4\",\n            \"language\": \"ja\",\n            \"author\": [\n                {\n                    \"family\": \"\u30a2\u30f3\u30c6\u30ca\u30cf\u30a6\u30b9\u682a\u5f0f\u4f1a\u793e\",\n                    \"given\": \"\"\n                }\n            ],\n            \"issued\": {\n                \"date-parts\": [\n                    [\n                        2016,\n                        5\n                    ]\n                ]\n            }\n        }\n    ]\n}<\/code><\/pre>\n<p>\u3053\u306eJSON\u3092\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u53d6\u308a\u8fbc\u3080\u306b\u306f\u6b21\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre><code>&lt;xsl:param name=\"input\" &gt;'exported-data.json'&lt;\/xsl:param&gt;\n...\n&lt;xsl:variable\u00a0as=\"map(*)\"\u00a0name=\"jsonMap\"\u00a0select=\"fn:json-doc($input)\"\/&gt;\n&lt;!-- \u307e\u305f\u306f --&gt;\n&lt;xsl:variable as=\"xs:string\" name=\"json-text\" select=\"fn:unparsed-text($input)\"\/&gt;\n&lt;xsl:variable as=\"map(*)\" name=\"jsonMap\" select=\"parse-json($json-text)\"\/&gt;\n<\/code><\/pre>\n<p>XML\u306b\u5909\u63db\u3057\u305f\u5148\u9031\u3068\u3001map\u3084array\u3092\u6d3b\u7528\u3059\u308b\u4eca\u56de\u306f\u3053\u306e\u5f8c\u304c\u307e\u3063\u305f\u304f\u7570\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u6b21\u306e\u8a18\u8ff0\u3067\u3001\u5148\u982d\u306etitle\u3092\u4e00\u606f\u3067\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n<pre><code>&lt;xsl:value-of select=\"map:get(array:head(map:get($jsonMap, 'items')), 'title')\" \/&gt;<\/code><\/pre>\n<p>\u307e\u305a\u3001\u6700\u3082\u5916\u5074\u306emap\u304b\u3089\u3001<code>items<\/code>\u306e\u30ad\u30fc\u3092\u6301\u3064\u8981\u7d20\u3092\u53d6\u5f97\u3057\u307e\u3059\uff08<code>map:get($jsonMap, 'items')<\/code>\uff09\u3002<br \/>\n\u30ad\u30fc<code>items<\/code>\u306e\u5024\u306farray\u578b\u3067\u3059\u3002\u3053\u306e\u307e\u307e<code>map:get()<\/code>\u3092\u884c\u304a\u3046\u3068\u3057\u3066\u3082\u3067\u304d\u307e\u305b\u3093\u304b\u3089\u3001array\u306e\u5148\u982d\u3092\u53d6\u308a\u51fa\u3059<code>array:head()<\/code>\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002\u3068\u3053\u308d\u3067\u4e0a\u306e\u8a18\u8ff0\u306f\u30d1\u30a4\u30d7\u6f14\u7b97\u5b50\u3092\u4f7f\u3048\u3070\u6b21\u306e\u3088\u3046\u306b\u66f8\u3051\u307e\u3059\u3002<\/p>\n<pre><code>&lt;xsl:value-of select=\"map:get($jsonMap, 'items') =&gt; array:head() =&gt; map:get('title')\" \/&gt;<\/code><\/pre>\n<p>map\u306earray\u3067\u306f\u3001<code>map:find()<\/code>\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3067\u6307\u5b9a\u3057\u305f\u30ad\u30fc\u306e\u5024\u3092\u914d\u5217\u3067\u5f97\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\u6319\u52d5\u306e\u8a73\u7d30\u306fXPath 3.1<sup>*1<\/sup>\u304bXSLT 3.0<sup>*2<\/sup>\u306e\u30da\u30fc\u30b8\u3092\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><code>type<\/code>\u306e\u5024\u304c\u4f55\u7a2e\u985e\u304b\u306b\u6c7a\u307e\u3063\u3066\u3044\u3066\u3001\u305d\u306e\u7a2e\u985e\u3092\u5143\u306bif\u6587\u306e\u5224\u5b9a\u3092\u3057\u305f\u3044\u306e\u3067\u3042\u308c\u3070\u3001\u6b21\u306e\u3088\u3046\u306b\u66f8\u3051\u307e\u3059\u3002<\/p>\n<pre><code>     &lt;xsl:variable as=\"map(*)\" name=\"item\" select=\"map:get($jsonMap, 'items') =&gt; array:head()\" \/&gt;\n      &lt;xsl:if\u00a0test=\"map:get($item,\u00a0\u00a0'type')\u00a0=\u00a0\u00a0'book'\u00a0or\u00a0'proceedings'\"&gt;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;xsl:value-of\u00a0select=\"map:get($item,\u00a0'type')\"\u00a0\/&gt; &lt;!-- book --&gt;\n\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/xsl:if&gt;<\/code><\/pre>\n<p>\u3082\u3061\u308d\u3093XML\u306e\u69cb\u9020\u306b\u5909\u63db\u3057\u3066\u3082\u540c\u3058\u3053\u3068\u306f\u3067\u304d\u307e\u3059\u304c\u3001\u3088\u308a\u4e00\u822c\u7684\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306b\u8fd1\u3044\u5f62\u3067\u6271\u3048\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>map\u3084array\u3068\u3057\u3066\u6271\u3046\u305f\u3081\u306b\u3001JSON\u30c6\u30ad\u30b9\u30c8\u3068\u3057\u3066\u8a18\u8ff0\u3057\u3066\u30d1\u30fc\u30b9\u3057\u305f\u308a\u3001<code>select=\"map{\"key\":value}\"<\/code>\u306e\u3088\u3046\u306a\u66f8\u304d\u65b9\u3092\u3059\u308b\u4ee5\u5916\u306b\u3001<code>&lt;xsl:map&gt;<\/code>\u3084<code>&lt;map-entry&gt;<\/code>\u3092\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>map\u306e\u64cd\u4f5c\u306f\u30a8\u30f3\u30c8\u30ea\u306e\u8ffd\u52a0\u3084\u30ad\u30fc\u6307\u5b9a\u3067\u306e\u524a\u9664\u306a\u3069\u306e\u4ed6\u3001<code>map:merge()<\/code>\u306b\u3088\u308bmap\u306e\u7d71\u5408\u3001<code>map:for-each()<\/code>\u306b\u3088\u308bmap\u8981\u7d20\u5358\u4f4d\u3067\u306e\u95a2\u6570\u9069\u7528\u306a\u3069\u304c\u53ef\u80fd\u3067\u3059\u3002array\u306e\u65b9\u306f<code>array:fold-left()<\/code>\u3068<code>array:fold-right()<\/code>\u306e\u7573\u307f\u8fbc\u307f\u95a2\u6570\u3084\u3001<code>array:for-each()<\/code>\u3067array\u306e\u8981\u7d20\u3054\u3068\u306b\u95a2\u6570\u9069\u7528\u306a\u3069\u306a\u3069\u3001XML\u5f62\u5f0f\u3092\u6271\u3046\u3088\u308a\u3082\u3059\u3063\u304d\u308a\u3057\u305f\u69cb\u6587\u3067\u8a18\u8ff0\u304c\u53ef\u80fd\u306a\u95a2\u6570\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u6ce8\u610f\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3053\u3068\u3068\u3057\u3066\u3001map\u3067\u3042\u308b\u304barray\u3067\u3042\u308b\u304b\u3092\u9593\u9055\u3048\u308b\u3068\u3046\u307e\u304f\u5024\u3092\u53d6\u308a\u51fa\u305b\u307e\u305b\u3093\u3002<var>$item<\/var>\u306f<code>node<\/code>\u3067\u3082\u306a\u3044\u306e\u3067\u3001\u76f4\u63a5<code>xml-to-json()<\/code>\u306f\u4f7f\u3048\u307e\u305b\u3093\u3002<\/p>\n<p>\u4ed5\u69d8\u3084Saxon\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3068\u306b\u3089\u3081\u3063\u3053\u3092\u3057\u306a\u304c\u3089\u7d39\u4ecb\u3057\u3066\u304d\u305fXSLT 3.0\u3068XPath 3.1\u306eJSON\u306e\u6271\u3044\u3067\u3059\u304c\u3001\u8aa4\u308a\u306a\u3069\u3042\u308a\u307e\u3057\u305f\u3089\u3054\u6307\u6458\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>*1 <a href=\"https:\/\/www.w3.org\/TR\/xpath-31\/\">https:\/\/www.w3.org\/TR\/xpath-31\/<\/a><br \/>\n*2 <a href=\"https:\/\/www.w3.org\/TR\/xslt-30\/\">https:\/\/www.w3.org\/TR\/xslt-30\/<\/a><\/p>\n<hr \/>\n<h2>\u53c2\u8003\u8cc7\u6599<\/h2>\n<ul style=\"list-style: none;\">\n<li>Saxonica &gt; Saxon &gt; Reference: XPath Syntax <a href=\"https:\/\/www.saxonica.com\/html\/documentation\/expressions\/\">https:\/\/www.saxonica.com\/html\/documentation\/expressions\/<\/a><\/li>\n<\/ul>\n<hr \/>\n<div><a href=\"https:\/\/www.antenna.co.jp\/AHF\/ahf_publication\/#XSLTTutorial\"><img decoding=\"async\" src=\"https:\/\/www.antenna.co.jp\/AHF\/ahf_publication\/img\/XSLT.png\" \/><br \/>\n\u300e\u30b9\u30bf\u30a4\u30eb\u30b7\u30fc\u30c8\u958b\u767a\u306e\u57fa\u790e<br \/>\nXML \u3068 FO \u3067\u7c21\u5358\u306a\u672c\u3092\u4f5c\u3063\u3066\u307f\u3088\u3046\u300f<\/a><br \/>\n<a href=\"https:\/\/www.antenna.co.jp\/dita\/\"><img decoding=\"async\" src=\"https:\/\/www.antenna.co.jp\/dita\/img\/dita_logo.png\" \/><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5148\u9031\u306fXML\u306e\u5f62\u306b\u3057\u305fJSON\u3092\u3001XML\u306b\u3057\u306a\u3044\u307e\u307e\u6271\u3046\u65b9\u6cd5\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002CSL\u306f\u3067\u3066\u304d\u307e\u305b\u3093\u3002 XPath 3.1*1\u3067\u540d\u524d\u306bJSON\u304c\u5165\u308b\u95a2\u6570\u306f4\u3064\u3067\u3059\u3002 fn:parse-json($json-text as [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47,16],"tags":[133,254,258,263],"class_list":["post-11996","post","type-post","status-publish","format-standard","hentry","category-xml-dita","category-structured-doc","tag-json","tag-xml","tag-xpath","tag-xslt"],"_links":{"self":[{"href":"https:\/\/blog.antenna.co.jp\/ILSoft2\/wp-json\/wp\/v2\/posts\/11996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.antenna.co.jp\/ILSoft2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.antenna.co.jp\/ILSoft2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.antenna.co.jp\/ILSoft2\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.antenna.co.jp\/ILSoft2\/wp-json\/wp\/v2\/comments?post=11996"}],"version-history":[{"count":0,"href":"https:\/\/blog.antenna.co.jp\/ILSoft2\/wp-json\/wp\/v2\/posts\/11996\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.antenna.co.jp\/ILSoft2\/wp-json\/wp\/v2\/media?parent=11996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.antenna.co.jp\/ILSoft2\/wp-json\/wp\/v2\/categories?post=11996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.antenna.co.jp\/ILSoft2\/wp-json\/wp\/v2\/tags?post=11996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}