Re: [xsl] Re: Querying an Active Directory memberOf Attribute

Subject: Re: [xsl] Re: Querying an Active Directory memberOf Attribute
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 02 Aug 2006 11:15:23 -0400
At 10:27 AM 8/2/2006, it was written:
As for using a node set as a kind of array and checking for the
existence of the desired substring in the text value of each node (in
this case, the equivalent of an array element), you need a mechanism
to cicle through all the nodes in the node set (all the "elements" in
the "array"). Otherwise, only the first node will be checked.

To do that, you'll need a recursive template...

Given a nodeset, in simpler cases one can ask for


$nodeset[contains(.,$string)]

to return any (all) members of $nodeset that contain a substring $string. This subset coerces to Boolean true when it has any members, so one can say

<xsl:when test="$nodeset[contains(.,$string)]">...</xsl:when>

and get the desired behavior. (And indeed one can inspect this subset to see what members it has, etc.)

Erik is correct that in more complex cases one has to resort to recursion. Because it is so cumbersome, however (relatively), and because simple string equivalence testing is so easy, another approach is simply to design around this problem. As Mike pointed out,

$nodesetA = $stringB

if *any* node in $nodesetA has string value $stringB.

Ordinarily I don't recommend "designing around problems", but conversely, it's also true that a good design is good precisely because it tends to avoid such problems. XSLT 1.0 was not built to support arbitrary queries over XML or even arbitrary transformations -- we were supposed to have XQuery for that, as indeed we will, and XSLT 2.0 along with it.

If confined to XSLT 1.0, one conceivable solution, accordingly, is to preprocess your input in such a way that the values you are looking for are normalized as single strings, and substring analysis (not the language's strength) is therefore avoided.

Another approach is to look to Dimitre's work with FXSL, which by taking advantage of quasi-functional features in XSLT (when it is permitted to process its own results with an extension function in 1.0) abstracts many such problems away, at the cost of mastering its concepts.

Cheers,
Wendell

Current Thread