From 6bb023b5310685be5c3eb89fe49fe6df05feae1f Mon Sep 17 00:00:00 2001 From: Wendell Piez Date: Tue, 14 Jul 2020 17:21:04 -0400 Subject: [PATCH] Implementing shell logic for producing standalone converter XSLTs from metaschema source. Many bug repairs and extensions. #53. --- .../MAKE-JSON-TO-XML-CONVERTER.xsl | 128 ----- .../MAKE-XML-TO-JSON-CONVERTER.xsl | 61 --- .../markdown-to-supermodel-xml-converter.xsl | 8 +- .../converter-gen/produce-json-converter.xsl | 14 +- .../converter-gen/produce-xml-converter.xsl | 40 +- .../converter-gen/supermodel-to-json.xsl | 235 +++++++-- .../converter-gen/supermodel-to-xml.xsl | 18 +- .../xslt-M4/make-metaschema-converters.xpl | 129 +++++ ...make-metaschema-xml-to-supermodel-xslt.xpl | 2 + ...-metaschema-MAKE-JSON-TO-XML-CONVERTER.xsl | 202 ++++++++ ...-metaschema-MAKE-XML-TO-JSON-CONVERTER.xsl | 182 +++++++ .../xslt-M4/testing/test-xml-conversions.xpl | 9 +- .../testing/test-xml-json-roundtrip.xpl | 21 +- .../xslt-M4/testing/testdata-supermodel.xml | 459 ++++++------------ 14 files changed, 937 insertions(+), 571 deletions(-) delete mode 100644 toolchains/xslt-M4/converter-gen/MAKE-JSON-TO-XML-CONVERTER.xsl delete mode 100644 toolchains/xslt-M4/converter-gen/MAKE-XML-TO-JSON-CONVERTER.xsl create mode 100644 toolchains/xslt-M4/make-metaschema-converters.xpl create mode 100644 toolchains/xslt-M4/nist-metaschema-MAKE-JSON-TO-XML-CONVERTER.xsl create mode 100644 toolchains/xslt-M4/nist-metaschema-MAKE-XML-TO-JSON-CONVERTER.xsl diff --git a/toolchains/xslt-M4/converter-gen/MAKE-JSON-TO-XML-CONVERTER.xsl b/toolchains/xslt-M4/converter-gen/MAKE-JSON-TO-XML-CONVERTER.xsl deleted file mode 100644 index c953f695d..000000000 --- a/toolchains/xslt-M4/converter-gen/MAKE-JSON-TO-XML-CONVERTER.xsl +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - - - - - - - - - - off - - - - - - - - - - ../compose/metaschema-collect.xsl - ../compose/metaschema-reduce1.xsl - ../compose/metaschema-reduce2.xsl - ../compose/metaschema-digest.xsl - - - ../compose/make-model-map.xsl - ../compose/unfold-model-map.xsl - ../compose/reduce-map.xsl - - produce-json-converter.xsl - - - - - - - - - - - - - - - - - - - - - - - - - - Processing architecture - - xml - - - - No file found at { $file } - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/toolchains/xslt-M4/converter-gen/MAKE-XML-TO-JSON-CONVERTER.xsl b/toolchains/xslt-M4/converter-gen/MAKE-XML-TO-JSON-CONVERTER.xsl deleted file mode 100644 index 9cb382c21..000000000 --- a/toolchains/xslt-M4/converter-gen/MAKE-XML-TO-JSON-CONVERTER.xsl +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - off - - - - - - - - - ../compose/metaschema-collect.xsl - ../compose/metaschema-reduce1.xsl - ../compose/metaschema-reduce2.xsl - ../compose/metaschema-digest.xsl - - - - - - - \ No newline at end of file diff --git a/toolchains/xslt-M4/converter-gen/markdown-to-supermodel-xml-converter.xsl b/toolchains/xslt-M4/converter-gen/markdown-to-supermodel-xml-converter.xsl index 5c1a922a0..8b106c1dd 100644 --- a/toolchains/xslt-M4/converter-gen/markdown-to-supermodel-xml-converter.xsl +++ b/toolchains/xslt-M4/converter-gen/markdown-to-supermodel-xml-converter.xsl @@ -13,15 +13,15 @@ - + - + - + - + @@ -141,7 +141,7 @@ - + @@ -160,8 +160,8 @@ - - Property is a flag; dropped when grabbing values + + Not keeping the flag here. diff --git a/toolchains/xslt-M4/converter-gen/produce-xml-converter.xsl b/toolchains/xslt-M4/converter-gen/produce-xml-converter.xsl index ac4c4cddd..bc31c2f53 100644 --- a/toolchains/xslt-M4/converter-gen/produce-xml-converter.xsl +++ b/toolchains/xslt-M4/converter-gen/produce-xml-converter.xsl @@ -1,12 +1,10 @@ @@ -54,8 +52,9 @@ -\-> --> - - + @@ -110,12 +109,12 @@ - + + + - - - + @@ -129,7 +128,7 @@ - + @@ -163,7 +162,9 @@ - + + + @@ -204,10 +205,13 @@ - - / - - + + + / + + + @@ -217,6 +221,14 @@ + + + + + + + + p | ul | ol | pre | h1 | h2 | h3 | h4 | h5 | h6 | table diff --git a/toolchains/xslt-M4/converter-gen/supermodel-to-json.xsl b/toolchains/xslt-M4/converter-gen/supermodel-to-json.xsl index e5ed5c542..863424e73 100644 --- a/toolchains/xslt-M4/converter-gen/supermodel-to-json.xsl +++ b/toolchains/xslt-M4/converter-gen/supermodel-to-json.xsl @@ -5,6 +5,7 @@ xpath-default-namespace="http://csrc.nist.gov/ns/oscal/metaschema/1.0/supermodel" xmlns="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xs math" + default-mode="write-json" version="3.0"> - - + + - + - + - + - + - + - - + + - + @@ -56,40 +57,40 @@ - + - + - + - + - + - + - + - + - - + + - + - + - + @@ -115,34 +116,206 @@ otherwise if the field is a scalar, its key is used, with no key if it has none otherwise the nominated key is used --> - + - + - + - + - + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + # + ## + ### + #### + ##### + ###### + + + + + + + + + + + + + | + + --- | + + + + + + + | + + + | + + + + + ``` + + + + ``` + + + + + + + + + + + + + + + + + + * + + + + + + + + + + + + 1. + + + + + + + ` + + ` + + + + * + + * + + + + ** + + ** + + + + " + + " + + + + + {{ + + }} + + + + [ + + ] + ( + + ) + + + + + ![ + + ] + ( + + + "{.}" + + ) + + + \ No newline at end of file diff --git a/toolchains/xslt-M4/converter-gen/supermodel-to-xml.xsl b/toolchains/xslt-M4/converter-gen/supermodel-to-xml.xsl index d9f8db662..33687e29b 100644 --- a/toolchains/xslt-M4/converter-gen/supermodel-to-xml.xsl +++ b/toolchains/xslt-M4/converter-gen/supermodel-to-xml.xsl @@ -1,26 +1,24 @@ - - + + - + - + - + - + @@ -28,7 +26,7 @@ - + diff --git a/toolchains/xslt-M4/make-metaschema-converters.xpl b/toolchains/xslt-M4/make-metaschema-converters.xpl new file mode 100644 index 000000000..1d71cf781 --- /dev/null +++ b/toolchains/xslt-M4/make-metaschema-converters.xpl @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/toolchains/xslt-M4/make-metaschema-xml-to-supermodel-xslt.xpl b/toolchains/xslt-M4/make-metaschema-xml-to-supermodel-xslt.xpl index 5477a3ee9..2e01a54aa 100644 --- a/toolchains/xslt-M4/make-metaschema-xml-to-supermodel-xslt.xpl +++ b/toolchains/xslt-M4/make-metaschema-xml-to-supermodel-xslt.xpl @@ -78,6 +78,8 @@ + + diff --git a/toolchains/xslt-M4/nist-metaschema-MAKE-JSON-TO-XML-CONVERTER.xsl b/toolchains/xslt-M4/nist-metaschema-MAKE-JSON-TO-XML-CONVERTER.xsl new file mode 100644 index 000000000..443eaaae9 --- /dev/null +++ b/toolchains/xslt-M4/nist-metaschema-MAKE-JSON-TO-XML-CONVERTER.xsl @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + + + off + + + + + + + + + + compose/metaschema-collect.xsl + compose/metaschema-reduce1.xsl + compose/metaschema-reduce2.xsl + compose/metaschema-digest.xsl + + + compose/make-model-map.xsl + compose/unfold-model-map.xsl + compose/reduce-map.xsl + + converter-gen/produce-json-converter.xsl + + + + + + + + + + + + + + + + + + + + + + + + JSON to XML conversion: pipeline + + + JSON to XML conversion: object filters + + + + + + + JSON to XML conversion: Markdown to markup inferencing + + + + + + JSON to XML conversion: Supermodel serialization as XML + + + + + + boo! + + + + + + + + + + + + + + + + + + + Processing architecture + + xml + + + + No file found at { $file } + + + + + + {{ $err:description }} + + + + + + + + + + + evaluating { $file } as URI relative to nominal source directory + + + + { $err:description } + + + + + + + + + + No XPath (XML) JSON found at { $file } - syntax of http://www.w3.org/2005/xpath-functions + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/toolchains/xslt-M4/nist-metaschema-MAKE-XML-TO-JSON-CONVERTER.xsl b/toolchains/xslt-M4/nist-metaschema-MAKE-XML-TO-JSON-CONVERTER.xsl new file mode 100644 index 000000000..61b91d30d --- /dev/null +++ b/toolchains/xslt-M4/nist-metaschema-MAKE-XML-TO-JSON-CONVERTER.xsl @@ -0,0 +1,182 @@ + + + + + + + + + + + + + + + + + + off + + + + + + + + + + compose/metaschema-collect.xsl + compose/metaschema-reduce1.xsl + compose/metaschema-reduce2.xsl + compose/metaschema-digest.xsl + + + compose/make-model-map.xsl + compose/unfold-model-map.xsl + compose/reduce-map.xsl + + + + + + + + + + + + + + + + + + + + + + + + + + XML to JSON conversion: pipeline + + + XML to JSON conversion: object filters + + + + + + XML to JSON conversion: Supermodel serialization as JSON + including markdown production + + + + + + + Supports either of two interfaces: + simply handle the XML as source (easier), producing the JSON as output, or + use arguments (equivalent to): -it from-xml produce=json file=[file] (mirrors the JSON converter interface) + + Parameter 'produce' supports acquiring outputs other than JSON: + produce=xpath produces XPath JSON (an XML syntax) + produce=supermodel produces intermediate (internal) 'supermodel' format + + Parameter setting 'json-indent=yes' produces JSON indented using the internal serializer + + json + + no + + + + + + { $json-indent='yes' } + + + + + + + + evaluating $file as URI relative to nominal source directory + + + + { $err:description } + + + + + + + + + + + + + + + + + + + + + + + + + + + { $err:description } + + + + + + + + + \ No newline at end of file diff --git a/toolchains/xslt-M4/testing/test-xml-conversions.xpl b/toolchains/xslt-M4/testing/test-xml-conversions.xpl index 8ea24a6c9..ac1cd6ce7 100644 --- a/toolchains/xslt-M4/testing/test-xml-conversions.xpl +++ b/toolchains/xslt-M4/testing/test-xml-conversions.xpl @@ -114,6 +114,7 @@ + @@ -124,6 +125,7 @@ + @@ -140,13 +142,14 @@ - - + + + diff --git a/toolchains/xslt-M4/testing/test-xml-json-roundtrip.xpl b/toolchains/xslt-M4/testing/test-xml-json-roundtrip.xpl index b00c3a0fd..a8ae2bb44 100644 --- a/toolchains/xslt-M4/testing/test-xml-json-roundtrip.xpl +++ b/toolchains/xslt-M4/testing/test-xml-json-roundtrip.xpl @@ -133,18 +133,12 @@ - - - - - - - - - + + + @@ -175,6 +169,11 @@ + @@ -184,9 +183,7 @@ - - - + diff --git a/toolchains/xslt-M4/testing/testdata-supermodel.xml b/toolchains/xslt-M4/testing/testdata-supermodel.xml index 7e60821ba..d2a8391dc 100644 --- a/toolchains/xslt-M4/testing/testdata-supermodel.xml +++ b/toolchains/xslt-M4/testing/testdata-supermodel.xml @@ -1,309 +1,166 @@ - - FIELD-1-ONLY - - - 1234abcd - - - true - - - fnv1 - FIELD-NAMED-VALUE - - - Here's some markup: make of it what you will! Even if it has ... * funky characters ` ... and even an some picture - - - - - 1 - field-groupable 1 - - - a - field-groupable 2 - - - 3 - field-groupable 3 - - - - - field-wrappable 1 - - - field-wrappable 2 - - - field-wrappable 3 - - - - - fbk1 - field-by-key 1 - - - fbk2 - field-by-key 2 - - - fbk3 - field-by-key 3 - - - - - fdvk1 - field-dynamic-value-key 1 - - - fdvk2 - field-dynamic-value-key 2 - - - fdvk3 - field-dynamic-value-key 3 - - - - -

Wrapped up prose

-

This is prose. All wrapped up.

-
-
- - -

Unwrapped prose

-

Here we have unwrapped prose....

-
-
- - - ASSEMBLY-1-ONLY / FIELD-1-ONLY + name="anthology" + gi="ANTHOLOGY" + key="ANTHOLOGY" + namespace="http://csrc.nist.gov/metaschema/ns/anthology"> + + + + editor + Wendell Piez + + + + + poetry + + + verse + + + + +

Demo anthology

+

Compiled for purposes of testing and demonstrating validations against constraints + defined by NIST Metaschema.

+
- - - - - assembly-groupable 1 / field-groupable 1 - - - assembly-groupable 1 / field-groupable 2 - - - assembly-groupable 1 / field-groupable 3 - - - - - - - assembly-groupable 2 / field-groupable 1 - - - assembly-groupable 2 / field-groupable 2 - - - assembly-groupable 2 / field-groupable 3 - - - - - - - assembly-groupable 3 / field-groupable 1 - - - assembly-groupable 3 / field-groupable 2 - - - assembly-groupable 3 / field-groupable 3 - - + + + + + + author + #w.h.auden + W.H. Auden + + + + 1954 + + + + quatrain + + + 4 + trochee + Guard, Civility, with guns + + + 4 + iamb + Your modes and your declensions: + + + 4 + trochee + Any lout can spear with ease + + + 4 + trochee + Singular Archimedes. + + + - - - - - assembly-wrappable 1 / field-wrappable 1 - - - assembly-wrappable 1 / field-wrappable 2 - - - assembly-wrappable 1 / field-wrappable 3 - + + + + + w.h.auden + + Wystan Hugh Auden + + + 1907-02-21 + 1973-09-29 + + + + + + + 1907-02-21 + 1973-09-29 + + + + + + - - - - assembly-wrappable 2 / field-wrappable 1 - - - assembly-wrappable 2 / field-wrappable 2 - - - assembly-wrappable 2 / field-wrappable 3 - - - - - - - assembly-wrappable 3 / field-wrappable 1 - - - assembly-wrappable 3 / field-wrappable 2 - - - assembly-wrappable 3 / field-wrappable 3 - - - - - - - abk1 - - - abk1.fbk1 - assembly-by-key 1 / field-by-key 1 - - - abk1.fbk2 - assembly-by-key 1 / field-by-key 2 - - - abk1.fbk3 - assembly-by-key 1 / field-by-key 3 - - - - - abk2 - - - abk2.fbk1 - assembly-by-key 1 / field-by-key 1 - - - abk2.fbk2 - assembly-by-key 1 / field-by-key 2 - - - abk2.fbk3 - assembly-by-key 1 / field-by-key 3 - - - - - abk3 - - - abk3.fbk1 - assembly-by-key 1 / field-by-key 1 - - - abk3.fbk2 - assembly-by-key 1 / field-by-key 2 - - - abk3.fbk3 - assembly-by-key 1 / field-by-key 3 - - - - - - - - nested FIELD-1-ONLY - - - +