[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: return type of a function returning namespaces?

Subject: Re: return type of a function returning namespaces?
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 9 Jun 2022 08:18:48 -0000
Re:  return type of a function returning namespaces?
Use as="namespace-node()*" (at least in XPath 3.1, I haven't checked exactly
when it was introduced).

Michael Kay
Saxonica

> On 9 Jun 2022, at 04:31, Graydon graydon@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Hello!
>
> So as part of an incumbent process, it turns out that the namespaces all
> have to be declared on the document element or the downstream processing
> fails.  That's not correct, but I can't fix the process, so I wrote the
> following to make sure all the required namespaces could be declared on
> the document element.
>
>
> <xsl:function name="local:getNamespaces">
>  <xsl:param name="thisDoc" as="document-node()"/>
>  <!-- group descendant elements by namespace URI because we don't completely
trust the prefix to be unique -->
>  <xsl:for-each-group select="$thisDoc/descendant-or-self::element()"
>    group-by="namespace-uri-from-QName(resolve-QName(name(.), .))">
>    <xsl:variable name="QName" as="xs:QName"
select="current-group()[1]/resolve-QName(name(.), .)"/>
>    <xsl:variable name="prefix" as="xs:string?"
select="prefix-from-QName($QName)"/>
>    <xsl:variable name="namespace" as="xs:anyURI?"
select="namespace-uri-from-QName($QName)"/>
>    <!-- don't create a namespace for the default namespace; only if there's
a defined prefix (empty string = false) -->
>    <xsl:if test="$prefix">
>      <xsl:namespace name="{$prefix}" select="$namespace"/>
>    </xsl:if>
>  </xsl:for-each-group>
> </xsl:function>
>
>
> It works, but I find myself wondering how I could declare the return
> type of the function.
>
> as="namespace()" does not work; namespace() isn't a node test.
>
> I realize this is a weird case that's a workaround for a bug elsewhere
> in the process, but wanting to be able to extract and manipulate a
> sequence of namespaces seems like a reasonable thing for a function to
> do.
>
> What am I missing?
>
>
> --
> Graydon Saunders  | graydonish@xxxxxxxxx
> CC&s oferC)ode, C0isses swC! mC&g.
> -- Deor  ("That passed, so may this.")

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.