How to determine the inner context node within an XSLT select
I'm trying to determine a subset of nodes stored in the variable objs by using a user defined function cube:is_active:
<xsl:variable name="active_cubes" select="$objs[cube:is_active(XXX) = 'TRUE']"/>
Since the function does not allow a local context I'm required to pass it as a parameter (denoted by XXX). However, the usual suspects "." or "current()" d开发者_开发技巧o not work since they refer to context node of the surrounding block and NOT to the current element of objs which is evaluated.
The only solution so far which DOES work is:
XXX=SOME_CHILD_TAG/..
But this is really ugly since it depends on the existence of the child tag for the parent node to work correctly.
Is there any other way? Thanks!
You need to use a node-set()
function that is supported by your xslt processor.
I.e.
<xsl:variable name="active_cubes" select="exsl:node-set($objs)[cube:is_active(XXX) = 'TRUE']"/>
The sample assumes that your processor supports the exsl:node-set funciton. Obviously you have to declare the namespace using xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
.
EDIT:
The context position described by current() or '.' should be the nth item in the node list in $objs
(see here). So therefore $objs[cube:is_active(.) = 'TRUE']
should work.
Check for common errors:
- whether $objs contains the right nodes,
- whether cube:is_active returns a string or a boolean,
- whether there is more than one node in $objs otherwise the predicate does not realy make sense. Instead you may try a
xsl:if
construct with atest
ofcube:is_active($objs) = 'TRUE'
精彩评论