Skip to content

Instantly share code, notes, and snippets.

@arolle
Created July 21, 2013 15:26
Show Gist options
  • Save arolle/6048870 to your computer and use it in GitHub Desktop.
Save arolle/6048870 to your computer and use it in GitHub Desktop.
XQuery Snippet that makes XML available to Javascript. To be used with @BaseXdb
(:
: Snippet that makes the XML from the variable $xml available
: to Javascript.
:)
let $xml := <p>my text</p>
! serialize(.,
<output:serialization-parameters>
<output:method value="xml"/>
<output:item-separator value=""/>
</output:serialization-parameters>
)
! replace(.,"\n","")
return
<script type="text/javascript">
var data = '{$xml}';
<![CDATA[
// creates div-Element containing the XML as stored in $xml
window.onload = function() {
var div = document.createElement('div');
div.innerHTML = data;
document.body.appendChild(div);
};
]]>
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment