xsl-list
[Top] [All Lists]

Re: [xsl] A polynomial time XSLT program that generates a list of compatible roommates?

2013-09-23 07:58:34



I think you want

$ saxon9 rm.xml rm.xsl
[Sally,Betsy] [Joan,Linda] [Sue,Carol] [Francine,Doris]
[Sally,Carol] [Joan,Linda] [Betsy,Sue] [Francine,Doris]


where rm.xml is your posted file and the xsl is

<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:f="data:,f">

<xsl:output method="text"/>

<xsl:template match="RoommateFinder">
  <xsl:sequence select="string-join(f:rm(Freshmen/Name),'&#10;')"/>
</xsl:template>

<xsl:key name="p" match="OkayToPairWith/Name" use="../../Name"/>

<xsl:function name="f:rm">
 <xsl:param name="l"/>
  <xsl:sequence select="
  if(empty($l)) then ('')
  else if (empty(key('p',$l[1],root($l[1]))[.=$l])) then ()
  else
   for $p in key('p',$l[1],root($l[1]))[.=$l]
   return
   for $s in f:rm($l[position()!=1][not(.=$p)])
   return
   concat('[',$l[1],',',$p,'] ',$s)"/>
</xsl:function>

</xsl:stylesheet>


If it's time complexity is too large, just blame Michael's optimiser:-)


David


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