Jan Hoeft wrote:
Hi,
is it possible to get the result tree and work on it?

I am able to do the transformation on my own via executeChildTemplates. But I have not found a way to process the result.

<xalan:component prefix="my" elements="countwords">
   <xalan:script lang="javascript">
       function countwords(context, elem){
           transf = context.getTransformer();
           transf.executeChildTemplates(elem,true);
           return "";
       }
   </xalan:script>
</xalan:component>

<xsl:template match="/">
   <my:countwords>
       <text>
           some words
           <xsl:value-of select="."/>
       </text>
   </my:countwords>
</xsl:template>
Instead of doing this, I would create an extension function to count words, then do the following:

<xsl:template match="/">
  <xsl:variable name="text">
        some words
        <xsl:value-of select="."/>
  </xsl:variable>

  <text count="{ext:count-words($text)}">
    <xsl:value-of select="$text"/>
  </text>
</xsl:template?

If the whitespace within the "text" element is not interesting, you could create a string variable, instead of a result tree fragment variable:

  <xsl:variable name="text" select="concat('some words ', .)" />

which is more efficient.

Note that it's also possible to write a recursive template to count words, if you don't want to write an extension function.

Dave

Reply via email to