This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: graph traversal



simplifying it a bit so your root document is in the same directory
as the others (so getting rid of your 'test/')
the following does I think do a breadth first walk over the graph
omitting nodes already seen.

It could probably be improved (this just doesn't report seen nodes,
it still processes them)

The actual order the nodes are reported is somewhat arbitrary as it
depends how the system orders nodes from different documents.

actually with xt I get

bash-2.01$ xt root.html graph2.xsl 
<?xml version="1.0" encoding="utf-8"?>
6 2 1 3  bash-2.01$ 

> but what I really want is "6 2 1 3".
> (Actually what I really want is "6 2 3 1", but that may be harder.)

so i only get half marks I suppose.




<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:template match="html">
  <xsl:call-template name="bfirst">
    <xsl:with-param name="todo" select="."/>
  </xsl:call-template>
</xsl:template>


<xsl:template name="bfirst">
  <xsl:param name="seen" select="/.."/>
  <xsl:param name="todo"/>
  <xsl:if test="not(string($todo[1]/@version) = $seen)">
  <xsl:value-of select="$todo[1]/@version"/>
  <xsl:text> </xsl:text>
 </xsl:if>
    <xsl:if test="count($todo) &gt;0">
 <xsl:call-template name="bfirst">
    <xsl:with-param name="seen" select="$seen|$todo[1]/@version"/>
    <xsl:with-param name="todo" 
           select="$todo[position() &gt; 1] | 
            document($todo[1]/a/@href)/html"/>
  </xsl:call-template>
  </xsl:if>
</xsl:template>


</xsl:stylesheet>


If that is not right (I only tested it on the one documenent) something
along thse lines could probably be made to work.

David



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]