title: XSLT - make xsl:analyze-string return string instead of sequence of strings?
body: <p>Is it possible to make <a href="http://www.w3.org/TR/xslt20/#analyze-string" rel="nofollow"><code>xsl:analyze-string</code></a> return one string instead of a <a href="http://www.w3.org/TR/xslt20/#element-sequence" rel="nofollow">sequence</a> of strings?</p>
  
  <p>Background: I'd like to use <a href="http://www.w3.org/TR/xslt20/#analyze-string" rel="nofollow"><code>xsl:analyze-string</code></a> in a <a href="http://www.w3.org/TR/xslt20/#stylesheet-functions" rel="nofollow"><code>xsl:function</code></a> that should encapsulate the pattern matching. Ideally, the function should return an <a href="http://www.w3.org/TR/xmlschema-2/#string" rel="nofollow"><code>xs:string</code></a> to be used as sort criteria in an <a href="http://www.w3.org/TR/xslt20/#element-sort" rel="nofollow"><code>xsl:sort</code></a> element.</p>
  
  <p>At the moment, i have to apply string-join() on every result of the function call since <a href="http://www.w3.org/TR/xslt20/#analyze-string" rel="nofollow"><code>xsl:analyze-string</code></a> returns a sequence of strings, and <a href="http://www.w3.org/TR/xslt20/#element-sort" rel="nofollow"><code>xsl:sort</code></a> doesn't accept such a sequence as sort criteria. See line 24 of the stylesheet:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet version="2.0"
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
          xmlns:my="www.my-personal-namespa.ce"
          xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  
  &lt;xsl:output indent="yes" method="xml"  /&gt;
  
  &lt;xsl:function name="my:sortierung" &gt;
      &lt;xsl:param name="inputstring" as="xs:string"/&gt;
      &lt;xsl:analyze-string select="$inputstring" regex="[0-9]+"&gt;
          &lt;xsl:matching-substring&gt;
              &lt;xsl:value-of select="format-number(number(.), '00000')" /&gt;
          &lt;/xsl:matching-substring&gt;
          &lt;xsl:non-matching-substring&gt;
              &lt;xsl:value-of select="." /&gt;
          &lt;/xsl:non-matching-substring&gt;
      &lt;/xsl:analyze-string&gt;
  &lt;/xsl:function&gt;
  
  &lt;xsl:template match="/input"&gt;
      &lt;result&gt;
      &lt;xsl:apply-templates select="value" &gt;
          &lt;xsl:sort select="string-join((my:sortierung(.)), ' ')" /&gt;
          &lt;/xsl:apply-templates&gt;
      &lt;/result&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="value"&gt;
      &lt;xsl:copy-of select="." /&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>with this input:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;input&gt;
      &lt;value&gt;A 1 b 120&lt;/value&gt;
      &lt;value&gt;A 1 b 1&lt;/value&gt;
      &lt;value&gt;A 1 b 2&lt;/value&gt;
      &lt;value&gt;A 1 b 1a&lt;/value&gt; 
  &lt;/input&gt;
  </code></pre>
  
  <p>In my example, is there a way to modify the xsl:function to return a xs:string instead of a sequence?</p>