[xquery-talk] Q: computed element and namespace

Hermann Stamm-Wilbrandt STAMMW at de.ibm.com
Fri Jan 31 00:12:58 PST 2014


>From (1):
In XPath Version 2.0, the namespace axis is deprecated and need not be
supported by a host language. A host language that does not support the
namespace axis need not represent namespace bindings in the form of nodes.

XQuery (eg. Zorba or DataPower) does not support the namespace axis.


<a><pre:b xmlns:pre="urn:u"/><pre:c xmlns:pre="urn:u"/></a>

can be created by computed element constructors (2) by this:

element {"a"}{
  (
    element {fn:QName("urn:u", "pre:b")}{},
    element {fn:QName("urn:u", "pre:c")}{}
  )
}

Is it true, that "equivalent" (not sure whether right term) XML
<a xmlns:pre="urn:u"><pre:b/><pre:c/></a>

cannot be created by computed element constructors in XQuery?


It can be created by XSLT 1.0+EXSLT stylesheet:

$ java -jar ~/Desktop/saxon6-5-5/saxon.jar dummy.xml compel.xsl ; echo
<a xmlns:pre="urn:u"><pre:b/><pre:c/></a>
$
$ cat compel.xsl
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:exslt = "http://exslt.org/common"
>
  <xsl:output omit-xml-declaration="yes" />

  <xsl:template match="/">
    <xsl:variable name="tmp">
      <xsl:element name="a">
        <xsl:attribute name="pre:ʎɯɯnp" xmlns:pre="urn:u"/>
        <xsl:element name="pre:b" xmlns:pre="urn:u"/>
        <xsl:element name="pre:c" xmlns:pre="urn:u"/>
      </xsl:element>
    </xsl:variable>

    <xsl:apply-templates select="exslt:node-set($tmp)/*"/>
  </xsl:template>

  <xsl:template match="*">
    <xsl:copy>
      <xsl:copy-of select="namespace::*|attribute::*[local-name
()!='ʎɯɯnp']"/>
      <xsl:apply-templates select="*"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
$


(1) http://www.w3.org/TR/xpath20/#dt-in-scope-namespaces
(2) http://www.w3.org/TR/xquery/#id-computedElements

Mit besten Gruessen / Best wishes,

Hermann Stamm-Wilbrandt
Level 3 support for XML Compiler team and Fixpack team lead
WebSphere DataPower SOA Appliances
https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/
https://twitter.com/HermannSW/
http://stamm-wilbrandt.de/GraphvizFiddle/
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294



More information about the talk mailing list