Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON to XML converter issue #1020

Closed
vikas-agarwal76 opened this issue Sep 13, 2021 · 6 comments · Fixed by #1027
Closed

JSON to XML converter issue #1020

vikas-agarwal76 opened this issue Sep 13, 2021 · 6 comments · Fixed by #1027
Assignees
Labels
Milestone

Comments

@vikas-agarwal76
Copy link

The command mentioned on https://github.com/usnistgov/OSCAL/tree/v1.0.0/xml for converting from JSON to XML format -

java -jar "saxon9he.jar" -xsl:"oscal_catalog_json-to-xml-converter.xsl" -o:"oscal-catalog.xml" -it json-file="oscal-catalog.json"

is not working. It seems the xsl files in https://github.com/usnistgov/OSCAL/tree/v1.0.0/xml/convert where updated in recent releases and the above command needs to be updated.

Kindly provide the updated command.

@david-waltermire
Copy link
Contributor

@wendellpiez Please provide a PR that updates the XML and JSON readmes as needed.

@wendellpiez
Copy link
Contributor

Apologies @vikas-agarwal76 this fell behind.

For now, try (with adjustments for quote marks)

> java -jar "saxon9he.jar" -xsl:"oscal_catalog_json-to-xml-converter.xsl" -o:"oscal-catalog.xml" -it:from-json file=yourjsonfile.json

But I am looking at the source; tomorrow I will test and update the readme.

Detail: the -it flag on the command line identifies the initial template

<xsl:template name="from-json">

the file parameter gives the path to your JSON file (relative or absolute URI)

<xsl:param name="file" as="xs:anyURI?"/>

Saxon command line syntax is given in detail at https://www.saxonica.com/documentation10/index.html#!using-xsl/commandline

@vikas-agarwal76
Copy link
Author

vikas-agarwal76 commented Sep 14, 2021

Thanks @wendellpiez The above command works.

But when I run the SSP json to xml convertor -
https://github.com/usnistgov/OSCAL/blob/v1.0.0/xml/convert/oscal_ssp_json-to-xml-converter.xsl
on a FedRAMP template SSP from -
https://github.com/GSA/fedramp-automation/blob/master/dist/content/templates/ssp/json/FedRAMP-SSP-OSCAL-Template.json
I get some warnings even though the file gets converted to XML -

Warning
XTDE0540: Ambiguous rule match for /map/map[1]/map[1]/array[6]/map[1]/string[1]
Matches both
"element(Q{http://www.w3.org/2005/xpath-functions}array)[(Q{http://www.w3.org/2001/XMLSchema}string(data(attribute::attribute(Q{}key)))) eq "responsible-parties"]/element(Q{http://www.w3.org/2005/xpath-functions}map)/element(Q{http://www.w3.org/2005/xpath-functions}string)[(Q{http://www.w3.org/2001/XMLSchema}string(data(attribute::attribute(Q{}key)))) eq "role-id"]" on line 799 of file:/Users/admin/Documents/MyData/data/Projects/fedramp-validation/nist-source/xml/convert/oscal_ssp_json-to-xml-converter.xsl
and "element(Q{http://www.w3.org/2005/xpath-functions}string)[(Q{http://www.w3.org/2001/XMLSchema}string(data(@key))) eq "role-id"]" on line 550 of file:/Users/admin/Documents/MyData/data/Projects/fedramp-validation/nist-source/xml/convert/oscal_ssp_json-to-xml-converter.xsl
Warning
XTDE0540: Ambiguous rule match for /map/map[1]/map[1]/array[6]/map[2]/string[1]
Matches both
"element(Q{http://www.w3.org/2005/xpath-functions}array)[(Q{http://www.w3.org/2001/XMLSchema}string(data(attribute::attribute(Q{}key)))) eq "responsible-parties"]/element(Q{http://www.w3.org/2005/xpath-functions}map)/element(Q{http://www.w3.org/2005/xpath-functions}string)[(Q{http://www.w3.org/2001/XMLSchema}string(data(attribute::attribute(Q{}key)))) eq "role-id"]" on line 799 of file:/Users/admin/Documents/MyData/data/Projects/fedramp-validation/nist-source/xml/convert/oscal_ssp_json-to-xml-converter.xsl
and "element(Q{http://www.w3.org/2005/xpath-functions}string)[(Q{http://www.w3.org/2001/XMLSchema}string(data(@key))) eq "role-id"]" on line 550 of file:/Users/admin/Documents/MyData/data/Projects/fedramp-validation/nist-source/xml/convert/oscal_ssp_json-to-xml-converter.xsl
Warning
XTDE0540: Ambiguous rule match for /map/map[1]/map[1]/array[6]/map[3]/string[1]
Matches both
"element(Q{http://www.w3.org/2005/xpath-functions}array)[(Q{http://www.w3.org/2001/XMLSchema}string(data(attribute::attribute(Q{}key)))) eq "responsible-parties"]/element(Q{http://www.w3.org/2005/xpath-functions}map)/element(Q{http://www.w3.org/2005/xpath-functions}string)[(Q{http://www.w3.org/2001/XMLSchema}string(data(attribute::attribute(Q{}key)))) eq "role-id"]" on line 799 of file:/Users/admin/Documents/MyData/data/Projects/fedramp-validation/nist-source/xml/convert/oscal_ssp_json-to-xml-converter.xsl
and "element(Q{http://www.w3.org/2005/xpath-functions}string)[(Q{http://www.w3.org/2001/XMLSchema}string(data(@key))) eq "role-id"]" on line 550 of file:/Users/admin/Documents/MyData/data/Projects/fedramp-validation/nist-source/xml/convert/oscal_ssp_json-to-xml-converter.xsl

and so on.

@wendellpiez
Copy link
Contributor

@vikas-agarwal76 @david-waltermire-nist that appears to be an honest bug in the converter. We will have to look at this separately.

We are currently developing alternate pathways supporting JSON-XML conversion so there may (also) be an interim solution to offer while we do so (what do you think DW)?

@vikas-agarwal76
Copy link
Author

@wendellpiez Based on our chat on gitter, here is the python code fragment that I am using to do the JSON to XML conversion programmatically (instead of from command line) -

           xslt_proc = saxon_proc.new_xslt30_processor()

            # set initial template name in XSL file
            xslt_proc.set_property('it', 'from-json')
            # Set the input json file parameter for conversion
            xslt_proc.set_parameter(
                'file', saxon_proc.make_string_value(str(file_path))
            )

            xml_str = xslt_proc.transform_to_string(
                stylesheet_file=str(xsl_path)
            )
            print(xml_str)

but I get "None" as output and there are no errors reported.
The "file_path" and "xsl_path" variables are same as I am using on the command line (which works).

@wendellpiez
Copy link
Contributor

As I understand it, we have not only interface enhancements (see usnistgov/metaschema#174) but a possible bug in the SSP (related to role-id), inasmuch as no runtime warning messages from template clashes should ever be emitted.

To close this issue we should ensure that the SSP converter in particular works with all valid inputs we have tried and that they come through cleanly and correctly without useless warnings.

wendellpiez added a commit to wendellpiez/metaschema that referenced this issue Sep 27, 2021
…time interfaces of generated JSON and XML converters
@david-waltermire david-waltermire linked a pull request Oct 5, 2021 that will close this issue
4 tasks
david-waltermire pushed a commit to usnistgov/metaschema that referenced this issue Nov 17, 2021
* Addressing #174 cf also usnistgov/OSCAL#1020 - adjusting runtime interfaces of generated JSON and XML converters
* Adding support for passing in JSON literal (to be tested); added template priority setting to intervene over template clashes #174
* Updating tests
* Correcting omission resulting in redundant path expressions (same step expressed multiply); tests; refinement of path matching to distinguish between flag matches signaled by 'attribute::' axis, vs field or assembly matches via 'child::' (or implicit) axis. With tests over current OSCAL SSP model.
* Touchups to unit tests
* Updated readme on OSCAL metaschema examples
@david-waltermire david-waltermire added this to the OSCAL 1.0.1 milestone Jan 30, 2022
nikitawootten-nist pushed a commit to nikitawootten-nist/metaschema-xslt that referenced this issue Jul 21, 2023
* Addressing #174 cf also usnistgov/OSCAL#1020 - adjusting runtime interfaces of generated JSON and XML converters
* Adding support for passing in JSON literal (to be tested); added template priority setting to intervene over template clashes #174
* Updating tests
* Correcting omission resulting in redundant path expressions (same step expressed multiply); tests; refinement of path matching to distinguish between flag matches signaled by 'attribute::' axis, vs field or assembly matches via 'child::' (or implicit) axis. With tests over current OSCAL SSP model.
* Touchups to unit tests
* Updated readme on OSCAL metaschema examples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants