Subject: Re: [xsl] differentiating between *the* document node and anonymous document nodes From: "Eliot Kimber eliot.kimber@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sun, 19 Mar 2023 14:09:31 -0000 |
The type document-node() is what you are looking for, but you may need to use the <xsl:document> constructor: <xsl:variable name=result as=document-node()> <xsl:document> <xsl:copy select=.> <xsl:apply-templates select=@*, node()/> </xsl:copy> </xsl:document> </xsl:variable> When no @as is specified the value of the variable will be a document node, per 9.3 Values of Variables and Parameters: If a variable-binding element<https://www.w3.org/TR/xslt-30/#dt-variable-binding-element> has no select attribute and has non-empty content (that is, the variable-binding element has one or more child nodes), and has no as attribute, then the content of the variable-binding element specifies the supplied value<https://www.w3.org/TR/xslt-30/#dt-supplied-value>. The content of the variable-binding element is a sequence constructor<https://www.w3.org/TR/xslt-30/#dt-sequence-constructor>; a new document is constructed with a document node having as its children the sequence of nodes that results from evaluating the sequence constructor and then applying the rules given in 5.7.1 Constructing Complex Content<https://www.w3.org/TR/xslt-30/#constructing-complex-content>. The value of the variable is then a singleton sequence containing this document node. For further information, see 9.4 Creating Implicit Document Nodes<https://www.w3.org/TR/xslt-30/#temporary-trees>. [https://www.w3.org/TR/xslt-30/#variable-values] So very important to specify @as when you *dont* want a document node (which is usually the case) and useful to specify @as=document-node() when you really do want a document node (for example, because you will be applying key() to the value of the variable, which requires a document and not just an element). This is a particularly subtle aspect of XSLT 2+ and can lead to some subtle bugs, especially when migrating from XSLT 1 (no @as) to XSLT 2+. Cheers, E. _____________________________________________ Eliot Kimber Sr Staff Content Engineer O: 512 554 9368 M: 512 554 9368 servicenow.com<https://www.servicenow.com> LinkedIn<https://www.linkedin.com/company/servicenow> | Twitter<https://twitter.com/servicenow> | YouTube<https://www.youtube.com/user/servicenowinc> | Facebook<https://www.facebook.com/servicenow> From: Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sunday, March 19, 2023 at 8:25 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Subject: Re: [xsl] differentiating between *the* document node and anonymous document nodes [External Email] ________________________________ Hi Dr. Kay, Thanks for the clarification on applying predicates to document-nodes in the previous email! I think my misunderstanding/misuse of terminology obscured my question. Is there some value of ??? in <xsl:variable name="result" as="???"> ... </xsl:variable> that is functionally identical to this: <xsl:variable name="result"> ... </xsl:variable> In which the variable can hold an arbitrary set of nodes while also providing contextual sibling relationships between them? * Chris From: Michael Kay michaelkay90@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Sent: Sunday, March 19, 2023 8:39 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] differentiating between *the* document node and anonymous document nodes As a follow-up question, is there an as="..." expression for an anonymous document node? I'm not sure what you mean. All document nodes are anonymous. Michael Kay Saxonica XSL-List info and archive<https://urldefense.com/v3/__http:/www.mulberrytech.com/xsl/xsl-list__ ;!!A4F2R9G_pg!fzjMLvEaOTSB1ToEYdrKhqhi90fAI5gjpe7x1m77A0z-B-eZJaKYK2kidZFb2_K 1Fe2zNOvAZHxmVtGvMSbMhBPy_EEqZIdg4pJBQ5TnzMenbXfGRWrM$> EasyUnsubscribe<https://urldefense.com/v3/__http:/lists.mulberrytech.com/unsu b/xsl-list/3380743__;!!A4F2R9G_pg!fzjMLvEaOTSB1ToEYdrKhqhi90fAI5gjpe7x1m77A0z -B-eZJaKYK2kidZFb2_K1Fe2zNOvAZHxmVtGvMSbMhBPy_EEqZIdg4pJBQ5TnzMenbXAryT3s$> (by email) XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list> EasyUnsubscribe<http://lists.mulberrytech.com/unsub/xsl-list/3453418> (by email<>)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] differentiating between *, Chris Papademetrious | Thread | Re: [xsl] differentiating between *, Chris Papademetrious |
Re: [xsl] differentiating between *, Chris Papademetrious | Date | Re: [xsl] differentiating between *, Chris Papademetrious |
Month |