title: Finding the longest cell in a table with XSLT 2.0
body: <p>Building on this topic:
  <a href="https://stackoverflow.com/questions/7923238/how-do-i-select-an-xml-node-with-the-longest-child-text-node-value-with-xpath">How do I select an XML node with the longest child #text node value with XPath?</a>
  I try to find the longest cell in column 1 of a table. Unfortunately I don't know how many ancestors the table has and there are sometimes several within one text- element which should be treated different.</p>
  
  <p>XML</p>
  
  
  
  <p></p>
  
  <pre><code>    &lt;text&gt;&lt;table cols="3" rows="2"&gt;
          &lt;row &gt;
              &lt;cell &gt;first cell first row&lt;/cell&gt;
              &lt;cell &gt;second cell first row
              &lt;/cell&gt;
              &lt;cell &gt;third cell first row
                      &lt;/cell&gt;
          &lt;/row&gt;
          &lt;row &gt;
              &lt;cell &gt;first cell second row&lt;/cell&gt;
              &lt;cell &gt;this is an incredible long text&lt;/cell&gt;
              &lt;cell /&gt;
          &lt;/row&gt;
      &lt;/table&gt;
  &lt;/text&gt;
  </code></pre>
  
  <p></p>
  
  <p>XSLT:</p>
  
  <pre><code>&lt;xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  
     &lt;xsl:template match="/"&gt;
        &lt;xsl:apply-templates/&gt;
     &lt;/xsl:template&gt;
  
       &lt;xsl:template match="table"&gt;
           &lt;xsl:variable name="longest1"&gt;
           &lt;xsl:sequence select=
              "/*/table/row/cell[1][not(string-length(.) &amp;lt; /*/table/row/cell[1]/string-length(.))]"/&gt;
           &lt;/xsl:variable&gt;
  &lt;xsl:value-of select="longest1"&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>The output of course should be "first cell second row", as the second column is not processed.
  I'm quite sure all I have to do is to fix the /* of this line:</p>
  
  <pre><code>&lt;xsl:sequence select=
                  "/*/table/row/cell[1][not(string-length(.) &amp;lt; /*/table/row/cell[1]/string-length(.))]"/&gt;
  </code></pre>
  
  <p>But I can't manage to see the solution.</p>