xsl-list
[Top] [All Lists]

RE: [xsl] xsl with dynamic xpath statement from param and variable

2007-09-06 14:42:29

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
      <xsl:output omit-xml-declaration="yes" indent="yes"/>
      <xsl:param name="argDictItem">RT.VAL.CANCELDATE</xsl:param>
      <xsl:variable name="sgl_qte">%27</xsl:variable>
      <xsl:variable name="xpathDictItem"
select="concat('group/dict[(_at_)id=',$sgl_qte,$argDictItem,$sgl_qt
e,']/val')
"/>

Firstly, you can't construct XPath expressions dynamically in standard XSLT.
You need a processor that offers an extension such as saxon:evaluate() or
dyn:evaluate().

Secondly, I can't see why you need it in this case. What's wrong with

<xsl:variable name="xpathDictItem" 
  select="group/dict[(_at_)id=concat($sgl_qte,$argDictItem,$sgl_qte)]/val"/>

(Except it seems a bit odd: what are those "%27" strings doing there?)

Thirdly, I don't know whether you can trust the caller who is supplying
$argDictItem, but if you do use xx:evaluate then you need to check that
$argDictItem doesn't contain any string delimiters.

      <xsl:template match="node()">
              <xsl:if test="name()!='item'">

Having a template that matches all nodes, and then immediately testing what
kind of node it is dealing with, seems a pretty odd thing to do.

Michael Kay
http://www.saxonica.com/


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>