[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: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 9 Jun 2022 04:41:34 -0000
Re:  return type of a function returning namespaces?
Maybe just use:

   as="node()"

This is still better than  not declaring the return type of the function at
all.

Here is a contrived example of using such a function:

<xsl:stylesheet version="2.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
 xmlns:my="my:my">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

  <xsl:template match="/">
    <xsl:element name="{concat(name(my:fun()), ':'[name(my:fun())])}myElem"
                 namespace="{my:fun()}"/>
  </xsl:template>

  <xsl:function name="my:fun" as="node()">
    <xsl:namespace name="xyz" >http://example.com</xsl:namespace>
  </xsl:function>
</xsl:stylesheet>

Cheers,
Dimitre

On Wed, Jun 8, 2022 at 8:31 PM 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.")
>
>
>

--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

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.