title: Is it possible to refactor XSLT tokenization handling out of a for-each and into a template?
body: <p>I have the following XML source file which includes a string listing prices in different currencies:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;menu&gt;
      &lt;item&gt;
          &lt;name id="A"&gt;Onion Rings&lt;/name&gt;
          &lt;prices&gt;$3.00,R45.00&lt;/prices&gt;
          &lt;kcal&gt;270&lt;/kcal&gt;
      &lt;/item&gt;
      &lt;!-- Some more items --&gt;
  &lt;/menu&gt;
  </code></pre>
  
  <p>and the following XSL file which tokenizes that prices string so that the output file has a separate price element for each price:</p>
  
  <p>
  </p>
  
  <pre><code>&lt;xsl:output method="xml" omit-xml-declaration="no" indent="yes" media-type="text/xml" /&gt;
  
  &lt;xsl:template match="/"&gt;
      &lt;foods&gt;
          &lt;xsl:apply-templates select="menu/item"&gt;
              &lt;xsl:sort select="name/@id" order="descending" /&gt;
          &lt;/xsl:apply-templates&gt;
      &lt;/foods&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="menu/item"&gt;
      &lt;food&gt;
          &lt;xsl:attribute name="id"&gt;
              &lt;xsl:value-of select="name/@id" /&gt;
          &lt;/xsl:attribute&gt;
          &lt;name&gt;&lt;xsl:value-of select="name" /&gt;&lt;/name&gt;
          &lt;prices&gt;
              &lt;xsl:for-each select="tokenize(prices, ',')"&gt;
                  &lt;price&gt;&lt;xsl:value-of select="." /&gt;&lt;/price&gt;
              &lt;/xsl:for-each&gt;
          &lt;/prices&gt;
          &lt;calories&gt;&lt;xsl:value-of select="kcal" /&gt;&lt;/calories&gt;
      &lt;/food&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p></p>
  
  <p>Which produces the output I want, but is there a way to factor out the for-each and have each item processed by a template instead? Something like:</p>
  
  <pre><code>&lt;food&gt;
      ...
      &lt;prices&gt;
         &lt;xsl:apply-templates select="tokenize(prices, ',')" /&gt;
      &lt;/prices&gt;
      ...
  &lt;/food&gt;
  
  &lt;template match="tokenize(prices, ',')"&gt;
      &lt;price&gt;&lt;xsl:value-of select="." /&gt;&lt;/price&gt;
  &lt;/template&gt;
  </code></pre>