Hi Folks,
 
Over the last few days I have been having some excellent exchanges with Michael
and have learned a lot.  I thought that I would summarize what I learned,
so that others can benefit as well.  Below is my summary.  Thanks Michael!  /Roger
 
 Understanding the Relationship of Nodes, Sequences, and Trees
 
(1) A node can belong to only one tree.
 
(2) A node may belong to any number of sequences.
 
(3) Axes always apply to the tree that the node is in.
    Axes never apply to the sequence that the node is in.
 
(4) When xsl:sequence is used in a sequence which has no
    parent node then the sequence contains the original node
    referenced by xsl:sequence and not a copy.
 
(5) When xsl:sequence is used in a sequence which has a parent
    node then the element that is referenced by xsl:sequence is
    copied.  Thus, the sequence is comprised of a copy and not
    the original.
 
(6) The preceding-sibling and following-sibling axes can only be
    used in a tree.  That is, they cannot be used in a sequence that
    does not have a parent node. (Nodes are "siblings" iff they have
    a common ancestor)
 
To understand these rules, let's consider an example.
 
Below is the XML document that my stylesheet operates upon:
 
<?xml version="1.0"?>
<FitnessCenter>
    <Member>
        <Name>Jeff</Name>
    </Member>
    <Member>
        <Name>David</Name>
    </Member>
    <Member>
        <Name>Roger</Name>
    </Member>
</FitnessCenter>
 
In my stylesheet I have created this variable:
 
<xsl:variable name="members" as="element()+">
    <xsl:sequence select="/FitnessCenter/Member[2]"/>
    <Member>
        <Name>Sally</Name>
    </Member>   
    <Member>
        <Name>Linda</Name>
    </Member>   
</xsl:variable>
 
Note that this variable contains a mix of elements - the first
element (the David Member) comes from the FitnessCenter.  The
second and third elements (Stacey and Linda) are defined within
the variable itself.
 
Further, note that this sequence does not have a parent node
(due to the presence of as="element()+".
 
A characteristic of xsl:sequence when used in a sequence that does
not have a parent node is that it does not create a copy of the node
that it references; instead, it uses the original node.  Thus,
$members[1] is referencing the original node:
 
    <Member>
        <Name>David</Name>
    </Member>
 
from the FitnessCenter.
 
Now let's consider the above rules in the context of this example.
 
(1) A node can belong to only one tree.
 
$members[1] references this node:
 
    <Member>
        <Name>David</Name>
    </Member>
 
This node belongs to the FitnessCenter tree.
 
$members[2] references this node:
 
    <Member>
        <Name>Stacey</Name>
    </Member>
 
This node belongs to the $members sequence. ($members
does not create a tree.  It is only creating a sequence
of nodes.)
 
(2) A node may belong to any number of sequences.
 
This node:
 
    <Member>
        <Name>David</Name>
    </Member>
 
belongs to both the FitnessCenter sequence as well as the
$members sequence.
 
(3) Axes always apply to the tree that the node is in.
    Axes never apply to the sequence that the node is in.
 
Consider this XSLT statement which uses the preceding-sibling
axis:
 
<xsl:copy-of select="$members[1]/preceding-sibling::*[1]"/>
 
$members[1] references the David node, which is in the
FitnessCenter tree.  Therefore, it is referencing David's preceding-sibling
in the FitnessCenter tree:
 
    <Member>
        <Name>Jeff</Name>
    </Member>
 
Likewise, this is referencing David's following-sibling in the
FitnessCenter tree:
 
<xsl:copy-of select="$members[1]/following-sibling::*[1]"/>
 
Output:
 
    <Member>
        <Name>Roger</Name>
    </Member>
 
Note that you cannot use preceding-sibling nor following-sibling
on $member[2] or $member[3] because these axes only apply to nodes
in a tree.  The Stacey Member and Linda Member are not in a tree - they
are only in a sequence.
 
(4) When xsl:sequence is used in a sequence which has no
    parent node then the sequence contains the original node
    referenced by xsl:sequence and not a copy.
 
Consider this variable declaration:
 
<xsl:variable name="members" as="element()+">
    <xsl:sequence select="/FitnessCenter/Member[2]"/>
    <Member>
        <Name>Sally</Name>
    </Member>   
    <Member>
        <Name>Linda</Name>
    </Member>   
</xsl:variable>
 
This variable is comprised of a sequence of nodes.  The sequence does not have a
parent node.  Therefore, the sequence is comprised of the original node.
 
(5) When xsl:sequence is used in a sequence which has a parent
    node then the element that is referenced by xsl:sequence is
    copied.  Thus, the sequence is comprised of a copy and not
    the original.
 
Consider this variable declaration:
 
<xsl:variable name="members">
    <xsl:sequence select="/FitnessCenter/Member[2]"/>
    <Member>
        <Name>Sally</Name>
    </Member>   
    <Member>
        <Name>Linda</Name>
    </Member>   
</xsl:variable>
 
Note the absence of as="element()+".  Thus, this Member sequence
has a document node as its parent.  Consequently, a *copy* of
/FitnessCenter/Member[2] is made and used in the sequence. So
this statement produces an empty output:
 
<xsl:copy-of select="$members[1]/preceding-sibling::*[1]"/>
 
(6) The preceding-sibling and following-sibling axes can only be
    used in a tree.  That is, they cannot be used in a sequence that
    does not have a parent node. (Nodes are "siblings" iff they
    have a common parent)
 
Therefore, for example, you cannot use following-sibling to get the
member that follows Sally:
 
<xsl:variable name="members" as="element()+">
    <xsl:sequence select="/FitnessCenter/Member[2]"/>
    <Member>
        <Name>Sally</Name>
    </Member>   
    <Member>
        <Name>Linda</Name>
    </Member>   
</xsl:variable>
 
This statement produces an empty output:
 
<xsl:copy-of select="$members[2]/following-sibling::*[1]"/>
 
However, in this version the sequence does have a parent (document)
node, so you can use following-sibling to retrieve the member that
follows Sally:
 
<xsl:variable name="members">
    <xsl:sequence select="/FitnessCenter/Member[2]"/>
    <Member>
        <Name>Sally</Name>
    </Member>   
    <Member>
        <Name>Linda</Name>
    </Member>   
</xsl:variable>
 
This statement:
 
<xsl:copy-of select="$members[2]/following-sibling::*[1]"/>
 
yields this output:
  
    <Member>
        <Name>Linda</Name>
    </Member>
 
An alternate form that will also work is this:
 
<xsl:variable name="members" as="element()+">
    <Members>
          <xsl:sequence select="/FitnessCenter/Member[2]"/>
          <Member>
              <Name>Sally</Name>
          </Member>   
          <Member>
              <Name>Linda</Name>
          </Member>   
    </Members>
</xsl:variable>
 
Note that the member sequence has a parent node (<Members>). 
Therefore, the following-sibling and preceding-sibling axes
can be used on the  member sequence, e.g.,
 
This statement:
 
<xsl:copy-of select="$members/Member[2]/following-sibling::*[1]"/>
 
yields this output:
  
    <Member>
        <Name>Linda</Name>
    </Member>