Subject: RE: [xsl] How to use generate-id() inside an xsl:function without a node available? From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Tue, 27 Feb 2007 22:25:46 -0000 |
> <xsl:function name="my:getNode"><node /></xsl:function> > <xsl:function name="my:getId"> <xsl:value-of select="generate-id(my:getNode())" /> </xsl:function> Yes, this is fine. But please get out of the habit of using xsl:value-of when you mean xsl:sequence, and please get into the habit of declaring the types of your functions! This should be <xsl:function name="my:getId as="xs:string"> <xsl:sequence select="generate-id(my:getNode())" /> </xsl:function> xsl:value-of is creating a text node, and because of the very identity issues we're discussing, it's very hard to optimize this away: if the return type is declared as xs:string the processor has some chance of recognizing that the text node is going to be atomized as soon as it's created, but really it's better not to create it in the first place. The cheapest solution is probably a text or comment node rather than an element, something like: <xsl:function name="my:getNode"><xsl:comment/></xsl:function> <xsl:function name="my:getId"> <xsl:value-of select="generate-id(my:getNode())" /> </xsl:function> Remember that an LRE like <node/> might be creating a lot of namespaces... Michael Kay http://www.saxonica.com/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] How to use generate-id() , Abel Braaksma | Thread | Re: [xsl] How to use generate-id() , Abel Braaksma |
Re: [xsl] How to use generate-id() , Abel Braaksma | Date | Re: [xsl] How to use generate-id() , Andrew Welch |
Month |