xsl-list
[Top] [All Lists]

RE: [xsl] XSLT2 xsl:sequence blocking ancestor refs?

2007-03-27 05:42:58
The construct

    <xsl:variable name="b">
      <xsl:sequence select="$p"/>
    </xsl:variable>

creates a temporary tree: $b is a document node, with a copy of $p attached
as a child. If you want $b to be the same node as $p, use

<xsl:variable name="b" select="$p"/>

or

    <xsl:variable name="b" as="node()">
      <xsl:sequence select="$p"/>
    </xsl:variable>

See http://www.w3.org/TR/xslt20/#temporary-trees

Michael Kay
http://www.saxonica.com/
 

-----Original Message-----
From: Marshall Schor [mailto:msa(_at_)schor(_dot_)com] 
Sent: 27 March 2007 13:32
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] XSLT2 xsl:sequence blocking ancestor refs?

Using xsl:sequence seems to chop off the ability to reference 
ancestors of selected nodes.
Is this working-as-designed?

Here's a quick demo.  In this piece of test code, the 
variable "b" has no parent, while the variable "a" does:

<xsl:variable name="in">
    <e1>
      <e2>
        <e3>
          <e4>yes</e4>
        </e3>
      </e2>
    </e1>
  </xsl:variable>

  <xsl:template match="anything_to_get_started">

    <xsl:variable name="p" select="$in/e1/e2/e3/e4"/>
    <xsl:variable name="a" select="$p"/>
    <xsl:message select="'parent of a'"/>
    <xsl:message select="$a/parent::node()"/>

    <xsl:variable name="b">
      <xsl:sequence select="$p"/>
    </xsl:variable>
    <xsl:message select="'parent of b'"/>
    <xsl:message select="$b/parent::node()"/>

  </xsl:template>

The output using Saxon 8.9

     [java] parent of a
     [java] <e3><e4>yes</e4></e3>
     [java] parent of b


-Marshall Schor


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>