title: XSLT apply template on every text node
body: <p>I have a complex transformation from one xml format to another and need to trim all the possible leading and tailing whitespaces on every text element after the transformation.</p>
  
  <p>XML input is something like:</p>
  
  <pre><code>&lt;Records&gt;
    &lt;Record&gt;
      &lt;FirstName&gt;FIRST&lt;/FirstName&gt;
      &lt;MiddleName&gt;MID&lt;/MiddleName&gt;
      &lt;LastName&gt;LAST&lt;/LastName&gt;
      &lt;VehType&gt;PCAR&lt;/VehType&gt;
      &lt;VehType2&gt;VN&lt;/VehType2&gt;
      &lt;VehMake&gt;CHEV&lt;/VehMake&gt;
      &lt;VehModel&gt;AST&lt;/VehModel&gt;
      &lt;VehColor&gt;DBL&lt;/VehColor&gt;
      &lt;VehVIN&gt;1234123&lt;/VehVIN&gt;
    &lt;/Record&gt;
  &lt;/Records&gt;
  </code></pre>
  
  <p>And stylesheet example is: </p>
  
  <pre><code>&lt;xsl:template match="Record"&gt;
      &lt;MyRecord&gt;
          &lt;NameRecord&gt;
              &lt;FirstName&gt;
                  &lt;xsl:value-of select="FirstName" /&gt;
              &lt;/FirstName&gt;
              &lt;MiddleName&gt;
                  &lt;xsl:value-of select="MiddleName" /&gt;
              &lt;/MiddleName&gt;
              &lt;LastName&gt;
                  &lt;xsl:value-of select="LastName" /&gt;
              &lt;/LastName&gt;
          &lt;/NameRecord&gt;
          &lt;VehicleRecord&gt;
              &lt;VehicleType&gt;
                  &lt;xsl:value-of select="VehType" /&gt;
              &lt;/VehicleType&gt;
              &lt;MakeOfCar&gt;
                  &lt;xsl:value-of select="VehMake" /&gt;
              &lt;/MakeOfCar&gt;
              &lt;ModelOfCar&gt;
                  &lt;xsl:value-of select="VehModel" /&gt;
              &lt;/ModelOfCar&gt;
              &lt;ColorPrimary&gt;
                  &lt;xsl:value-of select="VehColor" /&gt;
              &lt;/ColorPrimary&gt;
              &lt;VehicleIDNumber&gt;
                  &lt;xsl:value-of select="VehVIN" /&gt;
              &lt;/VehicleIDNumber&gt;
              &lt;YearOfCar&gt;
                  &lt;xsl:value-of select="VehYear" /&gt;
              &lt;/YearOfCar&gt;
          &lt;/VehicleRecord&gt;
      &lt;/MyRecord&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>But more complex with a lot of levels and inclusions. Problem is, any incoming xml element may contain data like <code>&lt;VehVIN&gt;   1234123  &lt;/VehVIN&gt;</code> and I need to trim leading and tailing whitespaces. Found <a href="https://stackoverflow.com/a/13974710">this</a> beautiful solution and tried to integrate it in to my stylesheet, but no luck.</p>
  
  <pre><code>&lt;xsl:template match="text()"&gt;
      &lt;xsl:call-template name="string-trim"&gt;
          &lt;xsl:with-param name="string" select="." /&gt;
      &lt;/xsl:call-template&gt;
  &lt;/xsl:template&gt;
  </code></pre>