I am playing with datasets in which namespaces are unhelpful because they make output harder to read. For production use, though, I want the namespaces to be there.
Ideally, I would like to tell BaseX to drop namespaces while serializing. Sometimes. Ideally, I would like to be able to set this as an option in a .bxs file. Is that possible?
Thanks!
Jonathan
On Thu, 2021-07-22 at 09:32 -0400, Jonathan Robie wrote:
I am playing with datasets in which namespaces are unhelpful because they make output harder to read. For production use, though, I want the namespaces to be there.
Ideally, I would like to tell BaseX to drop namespaces while serializing. Sometimes. Ideally, I would like to be able to set this as an option in a .bxs file. Is that possible?
You could run transform() with some simple XSLT to do this easily. Something like this maybe:
<xsl:stylesheet version="3" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclode-result-prefixes="#all"
<xsl:mode on-no-match="shallow-copy" /> <xsl:template match="*"> <xsl:element name="local-name()"> <xsl:apply-templates select="@*"/> xsl:apply-templates/ </xsl:element> </xsl:template>
And that can appear literally in your XQuery and passed as the stylesheet node to transform.
Thanks!
Jonathan
For testing purposes, you can always set the BaseX STRIPNS option when creating a database.
If you want to have your database untouched, a solution in XQuery looks as follows (…we should finally introduce a strip-namespaces() function):
declare function local:strip($n) { typeswitch($n) case document-node() return document { $n/(@*, node()) ! local:strip(.) } case element() return element { local-name($n) } { $n/(@*, node()) ! local:strip(.) } case attribute() return attribute { local-name($n) } { $n } default return $n };
local:strip( <x xmlns='x' a:a='A' xmlns:a='a'> <?pi PI ?>BLA<!-- COMMENT --> <c a:a='A'/> </x> )
On Thu, Jul 22, 2021 at 3:32 PM Jonathan Robie jonathan.robie@gmail.com wrote:
I am playing with datasets in which namespaces are unhelpful because they make output harder to read. For production use, though, I want the namespaces to be there.
Ideally, I would like to tell BaseX to drop namespaces while serializing. Sometimes. Ideally, I would like to be able to set this as an option in a .bxs file. Is that possible?
Thanks!
Jonathan
basex-talk@mailman.uni-konstanz.de