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

Subject: RE: [xsl] xsl with dynamic xpath statement from param and variable
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 6 Sep 2007 22:42:26 +0100
> <xsl:stylesheet xmlns:xsl="";
> 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[@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

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

<xsl:variable name="xpathDictItem" 

(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

Current Thread