Subject: Re: [xsl] Unique list of all linked documents From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Tue, 16 Apr 2002 10:07:13 +0100 |
Hi Edward, > I need to get a unique list of all documents that are linked to a > document. The list must include documents that are linked from > linked documents to an arbitrary level. You need a recursive template that will travel through the documents for you. Here's a recursive template that navigates through a set of documents, collecting together (and eventually returning) a space-separated list of their URLs: <xsl:template name="collectDocuments"> <!-- $documents holds the root nodes of documents to be processed, starting from the root node of the source document --> <xsl:param name="documents" select="/" /> <!-- $URLs holds the space-separated list of URLs --> <xsl:param name="URLs" /> <xsl:choose> <!-- if there are more documents to be processed... --> <xsl:when test="$documents"> <!-- ... collect together the URLs of those documents (as long as we haven't already got them --> <xsl:variable name="next" select="/documents/doc/@href[not(contains($URLs, .))]" /> <!-- call the template recursively, passing... --> <xsl:call-template name="collectDocuments"> <!-- the root nodes of those documents to $documents --> <xsl:with-param name="documents" select="document($next, .)" /> <!-- $URLs plus the space-separated URLs that we've just found --> <xsl:with-param name="URLs"> <xsl:value-of select="concat($URLs, ' ')" /> <xsl:for-each select="$next"> <xsl:value-of select="." /> <xsl:if test="position() != last()"> <xsl:text> </xsl:text> </xsl:if> </xsl:for-each> </xsl:with-param> </xsl:call-template> </xsl:when> <!-- if there aren't any more documents to be processed, return the value of $URLs --> <xsl:otherwise> <xsl:value-of select="$URLs" /> </xsl:otherwise> </xsl:choose> </xsl:template> Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Unique list of all linked doc, Edward . Middleton | Thread | RE: [xsl] count element content len, Jarno . Elovirta |
Re: [xsl] cross-reference & xsl:sor, Jeni Tennison | Date | [xsl] xsl and DB2, Jarkko . Moilanen |
Month |