Skip to content

Commit

Permalink
Merge pull request #709 from TEIC/jsonrng
Browse files Browse the repository at this point in the history
passing rng declarations through to a JSON object as string literal
  • Loading branch information
raffazizzi authored Nov 6, 2024
2 parents 1652202 + 50473aa commit a74859c
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 25 deletions.
17 changes: 12 additions & 5 deletions Test/expected-results/test33.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
[ ],
"datatype" :
{ "min" : "1",
"max" : "1" } },
"max" : "1",
"type" : "rng",
"rngContent" : "<rng:text xmlns=\"http:\/\/www.tei-c.org\/ns\/1.0\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\"\/>" } },

{ "onElement" : true,
"ident" : "r",
Expand All @@ -97,14 +99,19 @@
[ ],
"datatype" :
{ "min" : "1",
"max" : "1" } } ],
"max" : "1",
"type" : "rng",
"rngContent" : "<rng:text xmlns=\"http:\/\/www.tei-c.org\/ns\/1.0\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\"\/>" } } ],
"content" :
[
{ "type" : "ref" },
{ "type" : "rng",
"rngContent" : "<rng:ref xmlns=\"http:\/\/www.tei-c.org\/ns\/1.0\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" name=\"ref\"\/>" },

{ "type" : "oneOrMore" },
{ "type" : "rng",
"rngContent" : "<rng:oneOrMore xmlns=\"http:\/\/www.tei-c.org\/ns\/1.0\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\">\n <rng:ref name=\"macro.specialPara\"\/>\n <\/rng:oneOrMore>" },

{ "type" : "text" } ] } ],
{ "type" : "rng",
"rngContent" : "<rng:text xmlns=\"http:\/\/www.tei-c.org\/ns\/1.0\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\"\/>" } ] } ],
"classes" :
{ "models" :
[ ],
Expand Down
27 changes: 18 additions & 9 deletions Test/expected-results/test34.combined.json
Original file line number Diff line number Diff line change
Expand Up @@ -2300,11 +2300,14 @@
[ ],
"content" :
[
{ "type" : "ref" },
{ "type" : "rng",
"rngContent" : "<ref xmlns=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" xmlns:teix=\"http:\/\/www.tei-c.org\/ns\/Examples\" name=\"ref\"\/>" },

{ "type" : "oneOrMore" },
{ "type" : "rng",
"rngContent" : "<oneOrMore xmlns=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" xmlns:teix=\"http:\/\/www.tei-c.org\/ns\/Examples\"><ref name=\"macro.specialPara\"\/><\/oneOrMore>" },

{ "type" : "text" } ] },
{ "type" : "rng",
"rngContent" : "<rng:text xmlns=\"http:\/\/www.tei-c.org\/ns\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" xmlns:teix=\"http:\/\/www.tei-c.org\/ns\/Examples\"\/>" } ] },

{ "ident" : "cit",
"ns" : "http:\/\/blah.blah\/bar",
Expand All @@ -2328,11 +2331,14 @@
[ ],
"content" :
[
{ "type" : "ref" },
{ "type" : "rng",
"rngContent" : "<ref xmlns=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" xmlns:teix=\"http:\/\/www.tei-c.org\/ns\/Examples\" name=\"ref\"\/>" },

{ "type" : "oneOrMore" },
{ "type" : "rng",
"rngContent" : "<oneOrMore xmlns=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" xmlns:teix=\"http:\/\/www.tei-c.org\/ns\/Examples\"><ref name=\"macro.specialPara\"\/><\/oneOrMore>" },

{ "type" : "text" } ] },
{ "type" : "rng",
"rngContent" : "<rng:text xmlns=\"http:\/\/www.tei-c.org\/ns\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" xmlns:teix=\"http:\/\/www.tei-c.org\/ns\/Examples\"\/>" } ] },

{ "ident" : "citeData",
"ns" : "http:\/\/foo.foo\/foo",
Expand Down Expand Up @@ -8983,11 +8989,14 @@
[ ],
"content" :
[
{ "type" : "ref" },
{ "type" : "rng",
"rngContent" : "<ref xmlns=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" xmlns:teix=\"http:\/\/www.tei-c.org\/ns\/Examples\" name=\"ref\"\/>" },

{ "type" : "oneOrMore" },
{ "type" : "rng",
"rngContent" : "<oneOrMore xmlns=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" xmlns:teix=\"http:\/\/www.tei-c.org\/ns\/Examples\"><ref name=\"macro.specialPara\"\/><\/oneOrMore>" },

{ "type" : "text" } ] },
{ "type" : "rng",
"rngContent" : "<rng:text xmlns=\"http:\/\/www.tei-c.org\/ns\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" xmlns:teix=\"http:\/\/www.tei-c.org\/ns\/Examples\"\/>" } ] },

{ "ident" : "quotation",
"ns" : "http:\/\/foo.foo\/foo",
Expand Down
27 changes: 18 additions & 9 deletions Test/expected-results/test34.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@
[ ],
"content" :
[
{ "type" : "ref" },
{ "type" : "rng",
"rngContent" : "<rng:ref xmlns=\"http:\/\/www.tei-c.org\/ns\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" name=\"ref\"\/>" },

{ "type" : "oneOrMore" },
{ "type" : "rng",
"rngContent" : "<rng:oneOrMore xmlns=\"http:\/\/www.tei-c.org\/ns\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\">\n <rng:ref name=\"macro.specialPara\"\/>\n <\/rng:oneOrMore>" },

{ "type" : "text" } ] },
{ "type" : "rng",
"rngContent" : "<rng:text xmlns=\"http:\/\/www.tei-c.org\/ns\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\"\/>" } ] },

{ "ident" : "cit",
"ns" : "http:\/\/blah.blah\/bar",
Expand All @@ -93,11 +96,14 @@
[ ],
"content" :
[
{ "type" : "ref" },
{ "type" : "rng",
"rngContent" : "<rng:ref xmlns=\"http:\/\/www.tei-c.org\/ns\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" name=\"ref\"\/>" },

{ "type" : "oneOrMore" },
{ "type" : "rng",
"rngContent" : "<rng:oneOrMore xmlns=\"http:\/\/www.tei-c.org\/ns\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\">\n <rng:ref name=\"macro.specialPara\"\/>\n <\/rng:oneOrMore>" },

{ "type" : "text" } ] },
{ "type" : "rng",
"rngContent" : "<rng:text xmlns=\"http:\/\/www.tei-c.org\/ns\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\"\/>" } ] },

{ "ident" : "q",
"ns" : "http:\/\/blah.blah\/blah",
Expand All @@ -121,11 +127,14 @@
[ ],
"content" :
[
{ "type" : "ref" },
{ "type" : "rng",
"rngContent" : "<rng:ref xmlns=\"http:\/\/www.tei-c.org\/ns\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\" name=\"ref\"\/>" },

{ "type" : "oneOrMore" },
{ "type" : "rng",
"rngContent" : "<rng:oneOrMore xmlns=\"http:\/\/www.tei-c.org\/ns\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\">\n <rng:ref name=\"macro.specialPara\"\/>\n <\/rng:oneOrMore>" },

{ "type" : "text" } ] } ],
{ "type" : "rng",
"rngContent" : "<rng:text xmlns=\"http:\/\/www.tei-c.org\/ns\/1.0\" xmlns:bar=\"http:\/\/blah.blah\/bar\" xmlns:blah=\"http:\/\/blah.blah\/blah\" xmlns:rng=\"http:\/\/relaxng.org\/ns\/structure\/1.0\"\/>" } ] } ],
"classes" :
{ "models" :
[ ],
Expand Down
19 changes: 17 additions & 2 deletions odds/odd2json.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:j="http://www.w3.org/2005/xpath-functions"
xmlns:rng="http://relaxng.org/ns/structure/1.0"
exclude-result-prefixes="xs math"
version="3.0">

Expand Down Expand Up @@ -142,7 +143,7 @@
<xsl:sequence select="$source"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
</xsl:function>

<xsl:function name="tei:getClassType" as="xs:string">
<xsl:param name="context"/>
Expand Down Expand Up @@ -421,6 +422,13 @@
</xsl:for-each>
</j:array>
</xsl:when>
<xsl:when test="self::rng:*">
<!-- RNG elements are not converted to JSON, just serialized -->
<j:string key="type">rng</j:string>
<j:string key="rngContent">
<xsl:value-of select="serialize(.)" />
</j:string>
</xsl:when>
<xsl:otherwise>
<j:string key="type"><xsl:value-of select="local-name()"/></j:string>
</xsl:otherwise>
Expand Down Expand Up @@ -498,7 +506,14 @@
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</j:string>
</j:string>
<xsl:for-each select="rng:*">
<!-- RNG elements are not converted to JSON, just serialized -->
<j:string key="type">rng</j:string>
<j:string key="rngContent">
<xsl:value-of select="serialize(.)" />
</j:string>
</xsl:for-each>
<xsl:for-each select="tei:dataRef">
<j:map key="dataRef">
<xsl:call-template name="getDataRef"/>
Expand Down

0 comments on commit a74859c

Please sign in to comment.