This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: FXPath v0.3 + SAXON Implementation


Hi Dave,

> com:eval is fooling me.

My fault. There's perhaps more description in EXSLT - Functions at
http://www.jenitennison.com/xslt/exslt/functions/#function-com:eval.
Basically the implementation with EXSLT and with FXPath are hacks
because there's no support for dynamic evaluation of expressions in
XSLT.

> It transpires that it results in a template match, moded, with an
> expression as a param.
>
> so I have
>
>  <xsl:template match="*" mode="com:eval">
>     <xsl:param name="expr" select="."/>
>     ?????
>   </xsl:template>
>
> I'm *guessing* that the function evaluates to the application
> of the expression to the node value.

That's the point of com:eval(), but it'll only work with the EXSLT and
FXPath implementations if you provide some support for it in the form
of a moded template. Because there's no dynamic evaluation of
expressions in XSLT, the only way to support the function is to
convert the expressions yourself. So, if you're going to use
com:eval() on a load of nodes with a particular expression then you
should write a template to support it:

<xsl:template match="node()|@*" mode="com:eval">
   <xsl:param name="expr" select="'.'" />
   <xsl:choose>
      <xsl:when test="$expr = 'contains(., &quot;P&quot;)'">
         <xsl:value-of select="contains(., 'P')" />
      </xsl:when>
      <xsl:when test="$expr = 'starts-with(., &quot;foo&quot;)'">
         <xsl:value-of select="starts-with(., 'foo')" />
      </xsl:when>
      ...
      <xsl:otherwise>
         <xsl:value-of select="." />
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>

Of course if you're using a processor that supports dynamic evaluation
of expressions in XSLT then you can use a function from that processor
to do the work for you:

<xsl:template match="node()|@*" mode="com:eval">
   <xsl:param name="expr" select="'.'" />
   <xsl:choose>
      <xsl:when test="function-available('saxon:evaluate')">
         <xsl:value-of select="saxon:evaluate($expr)" />
      </xsl:when>
      ...
      <xsl:otherwise>
         <xsl:value-of select="." />
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>

But you might be better off just using that function rather than going
through com:eval() in the first place.

I hope that clears things up a bit?

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]