Sample conversion of an instance of CCTS XML to JSON format

Table of Contents

1. Sample conversion of an instance of CCTS XML to JSON format - CCTSXML2JSON.xsl
1.1. Invocation parameters and input file
1.2. Serializing the XML as JSON
1.3. Interpreting the CCTS properties
2. Index

Available invocation parameters

Available specialization parameter

1.  Sample conversion of an instance of CCTS XML to JSON format - CCTSXML2JSON.xsl

Filename: CCTSXML2JSON.xsl

$Id: CCTSXML2JSON.xsl,v 1.11 2020/04/12 16:40:00 admin Exp $

This is not to be considered final in any way. This is an exercise used in the prototyping of potential JSON serializations of CCTS documents by converting their XML to JSON syntax.

1.1. Invocation parameters and input file

Use the following invocation:

saxon9he -xsl:CCTSXML2JSON.xsl

The +gc= argument is optional. When supplied, the program leverages the type information available in the model definition as required by BDNDR 1.0. Without such information, the serialization uses anonymous typed content and preserves the attribute names from the XML (which are assumed in all cases to have been pre-validated with project schemas) as required by BDNDR 1.1.

method="text" (xsl:output)

The output is simple text without XML escaping.

indent select="'yes'" as="xsd:string" (xsl:param)

The output can be indented if desired; set to "no" for continuous

extension-content-regex select="'^Extension.*$'" (xsl:param)

The name for extension content

gc as="document-node(element(gc:CodeList))?" (xsl:param)

The CCTS dictionary is expressed as a genericode file of properties such as the example for UBL found at

When this file is absent, the serialization presumes the use of CEFACT Unqualified Data Type attribute names and anonymous-typed content.

1.2. Serializing the XML as JSON

c:BBIEbyName match="Row[Value[@ColumnRef='ComponentType']/SimpleValue='BBIE']" use="Value[@ColumnRef=('ComponentName','UBLName')]/SimpleValue" (xsl:key)

Keep track of each BBIE by its XML element name in GC file

match="/*" priority="1" (xsl:template)

Getting started...

c:abie (xsl:template)

Handle an ABIE by grouping its members by their name

match="*[matches(local-name(.),$extension-content-regex)]" priority="1" (xsl:template)

Catch an extension

match="*[*]" mode="#all" (xsl:template)

Handle an ASBIE (assumed by having element children)

match="*[not(*)]" mode="c:extension" (xsl:template)

Handle an extension BBIE

match="*[not(*)]" (xsl:template)

Handle a BBIE (assumed by having no element children)

c:indent(1) as="xsd:string" (xsl:function)

Indent the result if requested

Parameter node as="node()"

Where am I in the source nesting to determine depth?

c:nl(0) as="xsd:string?" (xsl:function)

Output a newline sequence if requested

c:escape(1) as="text()*" (xsl:function)

Escape JSON text on the way out

Parameter node as="node()"

The node whose text value is to be emitted.

1.3. Interpreting the CCTS properties

c:cctsAttr match="suppl" use="@attr" (xsl:key)

Find CCTS metadata name from attribute name

c:terms match="term" use="." (xsl:key)

Find CCTS representation term information for BBIE

c:cctInfo as="document-node()" (xsl:variable)

A distillation of attribute and metadata information distilled from

2. Index