Created
December 22, 2015 12:21
-
-
Save ScalaWilliam/3d1d4279d9fe4803d9a5 to your computer and use it in GitHub Desktop.
json transform with xquery 3.1 (saxon 9.7) and xslt. Only doing it in xquery because want it self contained
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"stuff":{"more":["more stuff!",{"thing":"more stuff!"}]}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.1"; | |
declare namespace xsl = "http://www.w3.org/1999/XSL/Transform"; | |
let $transformer := <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:xs="http://www.w3.org/2001/XMLSchema" | |
exclude-result-prefixes="xs" | |
version="3.0"> | |
<xsl:template match="text()[. = 'stuff']">more stuff!</xsl:template> | |
<xsl:template match="@*|node()"> | |
<xsl:copy> | |
<xsl:apply-templates select="@*|node()"/> | |
</xsl:copy> | |
</xsl:template> | |
</xsl:stylesheet> | |
let $json := '{"stuff": {"more": ["stuff", {"thing": "stuff"}]}}' | |
(: http://www.w3.org/TR/xpath-functions-31/#func-transform | |
http://www.saxonica.com/html/documentation/functions/fn/transform.html | |
:) | |
return xml-to-json(transform( | |
map { | |
"stylesheet-node": $transformer, | |
"source-node": fn:json-to-xml($json) | |
} | |
)?output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment