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

Re: differentiating between *the* document node and a

Subject: Re: 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
Re:  differentiating between *the* document node and  a
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:  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:  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

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.