xsl-list
[Top] [All Lists]

Re: [xsl] Error: XPTY0020: Leading '/' cannot select the root node of the tree containing the context item: the context item is an atomic value

2011-01-10 05:42:48
On 10/01/2011 11:35, Dietrich Bollmann wrote:
  <xsl:template match="/">
     <body>
       <xsl:for-each select="tokenize(example/bar/@ids, ',')">
         <xsl:value-of select="."/>:<xsl:value-of
select="key('index', .)" />
       </xsl:for-each>
     </body>
   </xsl:template>

The xsl:for-each select="tokenize()" changes the context item, so key() no longer knows which tree to search in. Change it to

  <xsl:variable name="root" select="/"/>
  <xsl:template match="/">
    <body>
      <xsl:for-each select="tokenize(example/bar/@ids, ',')">
        <xsl:value-of select="."/>:<xsl:value-of
select="key('index', ., $root)" />
      </xsl:for-each>
    </body>
  </xsl:template>

Michael Kay
Saxonica

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