This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
graph traversal
- To: xsl-list at mulberrytech dot com
- Subject: graph traversal
- From: Jeff Lansing <jeff at dtai dot com>
- Date: Thu, 17 Feb 2000 11:05:54 -0800
- Reply-To: xsl-list at mulberrytech dot com
How can I traverse a graph with XSL?
Specifically, hyperlinks encode a graph, as in the following four files:
K:\xslt\test>cat root.html
<html version = "6">
<a href = "left_branch.html"/>
<a href = "right_branch.html"/>
</html>
K:\xslt\test>cat left_branch.html
<html version = "2">
<a href = "leaf.html"/>
</html>
K:\xslt\test>cat right_branch.html
<html version = "3">
<a href = "leaf.html"/>
</html>
K:\xslt\test>cat leaf.html
<html version = "1"/>
K:\xslt\test>
I can do a tree traversal with the document() function, for example this
stylesheet:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="dir" select="'test/'"/>
<xsl:template match="html">
<xsl:value-of select="concat(@version, ' ')"/>
<xsl:for-each select="a">
<xsl:apply-templates select="document(concat($dir,@href))"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
when applied to root.html,
gives me "6 2 1 3 1", 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.)
Normally one marks the nodes of a graph when they're visited,
and then skips the marked nodes if they're seen again.
Can that be done in XSL?
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list