On 1 Aug 2006 at 16:48, Cailo wrote:
My problem is that because memberOf is an array within AD, the query is
only searching the first 'string' of the array and hence not returning
correct results. What I would like to do is to either query the entire
array or join each string within the array to create one long string,
then query the string. Please see below my script:
<xsl:template match="rf:attr[(_at_)name='memberOf']">
<attr name="GroupID">
<value>
<xsl:variable name="group" select="*" />
<xsl:choose>
<xsl:when test="contains($group,'Group_1')">100663298</xsl:when>
<xsl:when test="contains($group,'Group_2')">100663299</xsl:when>
<xsl:otherwise><xsl:value-of select="100663296" /></xsl:otherwise>
</xsl:choose>
</value>
</attr>
</xsl:template>
It's not clear to me whether $group is populated with a string or a
node set. Contains() always verifies the existence of a substring
within another string; it's not, as Michael Kay pointed out in other
words, an equivalent of PHP's in_array() or JavaScript's "if (var
prop in obj)".
I have done this previously with javascript and it worked fine however I
am unable to get this to work. Please see below the javascript:
Dim strGroups
If IsArray(varProp) Then
strGroups = (Join(varProp))
If (InStr(strGroups, "CN=Group_1") > 0 ) Then
objUser.IsUnprotected = 0
objUser.GroupID="Orlando"
End If
End If
I imagine you mean the above is pseudo-code for your actual
JavaScript. Well, JavaScript is a *very* different animal from XSLT.
Anyway, in the bit of code above it seems that you're checking for
the existence of "CN=Group_1" within strGroups, which in turn seems
to be the result of the concatenation of all varProps. This can be
done in XSLT; perhaps your problem is that you're doing something
wrong when trying to concatenate all the strings.
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, i.e. a template that
calls itself until all the nodes in the node set have been checked.
Here's a very simple example, just so you can understand the idea:
==============
test.xml
---------------------------
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<root>
<array>
<elem key="0">apple</elem>
<elem key="1">banana</elem>
<elem key="2">cherry</elem>
<elem key="3">orange</elem>
<elem key="4">raspberry</elem>
<elem key="5">watermelon</elem>
</array>
<search>
<item>banana</item>
<item>orange</item>
</search>
</root>
==============
==============
test.xsl
---------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/1999/XSL/Transform
http://www.w3.org/2004/11/schema-for-xslt20.xsd">
<xsl:output method="html" indent="yes" encoding="utf-8"/>
<xsl:template match="/">
<html>
<head>
<title>Results</title>
</head>
<body>
<xsl:apply-templates select="//search"/>
</body>
</html>
</xsl:template>
<xsl:template match="search">
<xsl:call-template name="in-array">
<xsl:with-param name="haystack"
select="/root/array/elem"/>
<xsl:with-param name="needle" select="item"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="in-array">
<xsl:param name="haystack"/>
<xsl:param name="needle"/>
<xsl:if test="$haystack and $haystack[1]">
<xsl:if test="$needle = $haystack[1]">
<p>Match: item <xsl:value-of
select="$haystack[1]/@key"/></p>
</xsl:if>
<xsl:call-template name="in-array">
<xsl:with-param name="haystack"
select="$haystack[position() >
1]"/>
<xsl:with-param name="needle" select="$needle"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
==============
My apologies if I misunderstood the nature of your problem. And
although I believe the example above can help you solve your problem,
it's possible that my preceding considerations are not entirely
accurate. I'm not Michael Kay! ;o)
Erik
_______________________________________________________
Você quer respostas para suas perguntas? Ou você sabe muito e quer compartilhar
seu conhecimento? Experimente o Yahoo! Respostas !
http://br.answers.yahoo.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>
--~--