Subject: [xsl] Spotting "cousin marriages" in a tree From: Phil Endecott <spam_from_xslt_list@xxxxxxxxxxxx> Date: Wed, 28 Jul 2004 22:18:50 +0100 |
<things> <thing id="1"> <child idref="2"/> <child idref="3"/> </thing> <thing id="2"/> <thing id="3"/> </things>
<tree id="1"> <tree id="2"/> <tree id="3"/> </tree>
<xsl:template match="thing"> <tree> <xsl:for-each select="child"> <xsl:apply-templates select="/things/thing[@id=current()/@idref]"/> </xsl:for-each> </tree> </xsl:template>
<xsl:key name="things-by-id" match="thing" use="@id"/> <xsl:template match="thing"> <tree> <xsl:for-each select="child"> <xsl:apply-templates select="key('things-by-id',@idref)"/> </xsl:for-each> </tree> </xsl:template>
<things> <thing id="1"> <child idref="2"/> <child idref="3"/> </thing> <thing id="2"> <child idref="4"/> </thing> <thing id="3"> <child idref="4"/> </thing> <thing id="4"/> </things>
<tree id="1"> <tree id="2"> <tree id="4"/> </tree> <tree id="3"> <tree id="4"> </tree> </tree>
<tree id="1"> <tree id="2"> <tree id="4"/> </tree> <tree id="3"> <error/> </tree> </tree>
<things> <thing id="1"> <child idref="2"/> <child idref="3"/> </thing> <thing id="2"/> <thing id="3"/> <thing id="9"> <child idref="2"/> </thing> </things>
<xsl:template match="/"> <xsl:variable name="n"> <xsl:apply-templates select="things/thing[1]"/> (as above) </xsl:variable> <xsl:apply-templates select="exsl:node-set($n)" mode="remove-dupes"/> </xsl:template>
<xsl:template match="tree" mode="remove-dupes"> <xsl:choose> <xsl:when test="preceding::tree[@id=current/@id]"> <error/> </xsl:when> <xsl:otherwise> <tree id="{@id}"> <xsl:apply-templates mode="remove-dupes"/> </tree> </xsl:otherwise> </xsl:choose> </xsl:template>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Yet Another Sorting Probl, Mukul Gandhi | Thread | RE: [xsl] Spotting "cousin marriage, Michael Kay |
Re: [xsl] And operator usage in XSL, J.Pietschmann | Date | Re: [xsl] And operator usage in XSL, john farrow |
Month |