[xsl] determining if 2 sequences of strings intersect

Subject: [xsl] determining if 2 sequences of strings intersect
From: Robert Koberg <rob@xxxxxxxxxx>
Date: Fri, 26 Jun 2009 14:13:14 -0700

Is there an easy way to determine whether 2 sequences of xs:string+ intersect. I am not able to use:

$seq1 intersect $seq2

because they need to be nodes.

An example with my lame(?) solution at the bottom:

I have a sequence of 'role' elements, e.g.

 <dbo.ROLE USER_ID="19955" ROLE="CAEMP"/>
 <dbo.ROLE USER_ID="19955" ROLE="INCPL"/>
 <dbo.ROLE USER_ID="19955" ROLE="MNGR"/>
 <dbo.ROLE USER_ID="19955" ROLE="NewHire"/>
 <dbo.ROLE USER_ID="19955" ROLE="NONHIEMP"/>
 <dbo.ROLE USER_ID="19955" ROLE="VEHALLW"/>

which is converted to a sequence of xs:string by:

<xsl:with-param name="roles"
 select="for $r in $roles return string($r/@ROLE)"

and I have an attribute that identifies role restrictions in another document context, e.g.

<task roleRestrictions="CAEMP VEHALLW"/>

which is converted to a sequence by:

<xsl:variable name="restrictions"
 select="tokenize(@roleRestrictions, ' ')"

So, what I am doing to get a value to show as true or false in a table cell is:

select="not(empty(index-of(f:has-role($roles, $restrictions), true())))"/>


 <xsl:function name="f:has-role" as="xs:boolean+">
   <xsl:param name="roles" as="xs:string+"/>
   <xsl:param name="restrictions" as="xs:string+"/>
   <xsl:sequence select="for $r in $restrictions return
     if (index-of($roles, $r)) then true() else false()"/>

Is there a better way?


Current Thread