tags:

views:

19

answers:

1

Hi there!

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()" do 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!

A: 

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 a test of cube:is_active($objs) = 'TRUE'
Obalix
I think the node set problem is handled correctly by the fact that I'm using XSLT2.0. But what about the XXX?
Marcus Rickert
Please see my edit.
Obalix
Mea maxima culpa. The error was in the function cube:is_active() which did not check the correct attribute. Unfortunately, the code to check the correctness of the function also had an error which made me believe that it was correct. Apparently, at one point I simultenously corrected the error in the function and changed the XXX to "SOME_CHILD_TAG/.." mistaking the latter for the solution :-(So, it does actually work with "." as context! :-)
Marcus Rickert