This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 28662 - Editorial: Example for fn:json-to-xml
Summary: Editorial: Example for fn:json-to-xml
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Functions and Operators 3.1 (show other bugs)
Version: Candidate Recommendation
Hardware: PC Windows NT
: P2 minor
Target Milestone: ---
Assignee: Michael Kay
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-20 14:47 UTC by Christian Gruen
Modified: 2016-12-16 19:55 UTC (History)
0 users

See Also:


Attachments

Description Christian Gruen 2015-05-20 14:47:38 UTC
In the "Examples" section of fn:json-to-xml, it's a bit surprising to have code in the XSLT syntax. Maybe it could be replaced with the following equivalent example:

  let $jsonstr := unparsed-text('http://example.com/endpoint')
  let $options := map {
    'liberal': true(),
    'fallback': function($char as xs:string) as xs:string {
      let $c0chars := map {
        '\u0000':'[NUL]',
        '\u0001':'[SOH]',
        '\u0002':'[STX]',
        ...
        '\u001E':'[RS]',
        '\u001F':'[US]'
      }
      let $replacement := $c0chars($char)
      return if (exists($replacement))
        then $replacement
        else error(xs:QName('err:invalid-char'), 
          'Error: ' || $char || ' is not a terminal control char.')
    }
  }
  return json-to-xml($jsonstr, $options)
Comment 1 Michael Kay 2015-05-29 10:13:06 UTC
Thanks for the suggestion. The XSLT example was there because of my laziness when moving the spec from XSLT 3.0. I have adopted your revision, except to replace

let $x:=A let $y:=B return C

by

let $x:=A, $y:=B return C

to make it valid in XPath as well as XQuery.