xsl-list
[Top] [All Lists]

Re: [xsl] Question about variable definition and types

2008-03-07 08:03:21
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
Lösungen und Training, FrameScript, XML/XSL, Unicode
<http://cap-studio.de/> -- Tel. +49 (9131) 28747




--~------------------------------------------------------------------
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>
--~--