title: XSLT: A sequence of more than one item is not allowed as the first argument of concat()
body: <p>I am trying to generate a pagelist which consists of a concatenation of the id of various divs (@chapter)|(@part). My problem stems from nested structures: @part can contain any number of @chapter. I only want to select the id of the last ancestor of a page number in document order.</p>
  
  <p>Below is a snippet of the XML:</p>
  
  <pre><code>&lt;text&gt;
      &lt;div class="part" id="s9781483352947.i870"&gt;
          &lt;a class="page" id="pbr-31"/&gt;
          &lt;h1 class="title"&gt;Part 1&lt;/h1&gt;
          &lt;p&gt;This is a paragraph.&lt;/p&gt;
          &lt;p&gt;This is a paragraph.&lt;/p&gt;
          &lt;div class="chapter" id="s9781483352947.n3.i884"&gt;
              &lt;a class="page" id="pbr-34"/&gt;
              &lt;h1 class="title"&gt;Chapter 1&lt;/h1&gt;
              &lt;p&gt;This is a paragraph&lt;/p&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/text&gt;
  </code></pre>
  
  <p>And below is my XSLT:</p>
  
  <pre><code>&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      exclude-result-prefixes="xs"
      version="2.0"&gt;
  
      &lt;xsl:template match="/"&gt;
      &lt;xsl:element name="nav"&gt;
          &lt;xsl:element name="h1"&gt;
              &lt;xsl:value-of select="'Pages'"/&gt;
          &lt;/xsl:element&gt;
          &lt;xsl:element name="ol"&gt;
              &lt;xsl:apply-templates mode="pagelist" select="//a[@class='page']"/&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:element&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="a[@class='page']" mode="pagelist"&gt;
          &lt;xsl:variable name="html" select="concat(ancestor::div[@class='chapter'][1]/@id | ancestor::div[@class='part'][1]/@id,'.xhtml#page')"/&gt;
          &lt;xsl:variable name="pagenumber" select="substring-after(@id,'-')"/&gt;
          &lt;xsl:element name="li"&gt;
              &lt;xsl:element name="a"&gt;
                      &lt;xsl:attribute name="href" select="concat($html,$pagenumber)"/&gt;
                      &lt;xsl:value-of select="substring-after(@id,'-')"/&gt;
                  &lt;/xsl:element&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>However, I keep getting the error message: A sequence of more than one item is not allowed as the first argument of concat(). Obviously my XPath is selecting multiple strings in the first argument due to the @part and @chapters. How do I limit the selection to the first ancestor of a class='page'?</p>
  
  <p>This is the desired ouput for the above sample:</p>
  
  <pre><code>&lt;nav&gt;
      &lt;h1&gt;Pages&lt;/h1&gt;
      &lt;ol&gt;
          &lt;li&gt;
              &lt;a href="s9781483352947.i870.xhtml#page31"&gt;31&lt;/a&gt;
          &lt;/li&gt;
          &lt;li&gt;
              &lt;a href="s9781483352947.n3.i884.xhtml#page34"&gt;34&lt;/a&gt;
          &lt;/li&gt;
      &lt;/ol&gt;
  &lt;/nav&gt;
  </code></pre>