Re: [xsl] Question about variable definition and types

Subject: Re: [xsl] Question about variable definition and types
From: Michael Müller-Hillebrand <mmh@xxxxxxxxxxxxx>
Date: Fri, 7 Mar 2008 16:02:55 +0100
Andrew and David,

Thanks a lot -- even on Friday afternoon one can learn some
interesting XSL!

Am 07.03.2008 um 11:43 schrieb David Carlisle:

If you go

<xsl:variable name="a2" as="element()*">
  <xsl:sequence select="a"/>
</xsl:variable>

Then in both cases the a element nodes are siblings, but

in $a2 they are the original a nodes in the source document (so
necessarily siblings as they are selected by the xpath "a" so all
children of the current node at that point. In this case $a2 holds
these
nodes, and they are (still) siblings, but they may have other siblings
not contained in the variable, and their parent node is similarly not
cotained in the variable.

If I process the content of $a2 I would assume that preceding/ following-sibling axis only "sees" the siblings in the variable. Your explanation makes me thinking (and a quick test with Kernow's sandbox ensures that) this is not true.

If I have

<root>
  <a/>
  <b/>
  <a/>
  <a/>
  <c/>
</root>

<xsl:template match="root">
  <xsl:variable name="a2" as="element()*">
    <xsl:sequence select="a"/>
  </xsl:variable>
  <xsl:copy>
    <xsl:for-each select="$a2">
      <xsl:copy>
        <xsl:attribute name="pos" select="position()"/>
        <xsl:attribute name="pre" select="name(preceding-sibling::*
[1])"/>
      </xsl:copy>
    </xsl:for-each>
  </xsl:copy>
</xsl:template>

I get

<root>
   <a pos="1" pre=""/>
   <a pos="2" pre="b"/>
   <a pos="3" pre="a"/>
</root>

How would I access the preceding/following siblings from "inside" the
variable with the as attribute?

- Michael

--
_______________________________________________________________
Michael M|ller-Hillebrand: Dokumentations-Technologie
Adobe Certified Expert, FrameMaker
Lvsungen und Training, FrameScript, XML/XSL, Unicode
<http://cap-studio.de/> -- Tel. +49 (9131) 28747

Current Thread