xsl-list
[Top] [All Lists]

[xsl] determining if 2 sequences of strings intersect

2009-06-26 17:13:42
Hi,

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"
 as="xs:string+"
 select="for $r in $roles return string($r/@ROLE)"
 tunnel="yes"/>


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, ' ')"
 as="xs:string+"/>


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

<xsl:sequence
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()"/>
 </xsl:function>


Is there a better way?

thanks,
-Rob

--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>