[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] forward references from non-ordered input?
Subject: [xsl] forward references from non-ordered input? From: Graham Seaman <graham@xxxxxxxxx> Date: Thu, 13 Sep 2001 13:24:46 +0100 (BST) |
Hi, I have a set of input documents with unordered elements, some of which may or may not be present in any one document. I need to be able to output the transformed elements in a fixed order, the output containing forward references from one element to the next. My first thought (maybe very naive - I'm a a beginner at this) was to create a variable containing the input elements as a list of tree fragments in a fixed order, then use a recursive routine to pop them off the list, with the ability to refer to other elements by their position in the variable list. Neither of the two xsl libraries I've tried (libXSL and Xalan) accept this, but I don't know how to read the error messages. From the FAQ I get the impression it may be because of limitations on what you can do with tree fragments, but I'm not sure. Is it possible to do it this way and am I just suffering from minor syntax errors, or is there a more XSL-y way to do it? Below is a simplified sketch of what I have at the moment. Thanks for any help, Graham --------------------------------------------------------------- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" > <xsl:template match="main"> <xsl:variable name="nav-list"> <nav> <xsl:if test="blah[@foo='abc']"> <navitem> <xsl:copy-of select="blah[@foo='abc']"/> </navitem> </xsl:if> <xsl:if test="blah[@foo='def']"> <navitem> <xsl:copy-of select="blah[@foo='def']"/> </navitem> </xsl:if> </nav> </xsl:variable> <xsl:call-template name="do-all"> <xsl:with-param name="nav-list" select="$nav-list/nav/navitem"/> <xsl:with-param name="count" select="0"/> </xsl:call-template> </xsl:template> <xsl:template name="do-all"> <xsl:param name="count" select="0"/> <xsl:param name="nav-list" select="."/> <xsl:choose> <xsl:when test="$nav-list[1]"> <xsl:variable name="this" select="$nav-list[1]"/> <xsl:choose> <xsl:when test="$this[@foo='def']"> DEF </xsl:when> <xsl:when test="$this[@foo='abc']"> ABC </xsl:when> <xsl:otherwise> NOTHING FOUND </xsl:otherwise> </xsl:choose> <!-- now recurse --> <xsl:call-template name="do-all"> <xsl:with-param name="count" select="$count+1"/> <xsl:with-param name="nav-list" select="$nav-list[position()!=1]"/> </xsl:call-template> </xsl:when> <!-- reached the end - exit --> <xsl:otherwise></xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] catching the last node st, Michael Kay | Thread | Re: [xsl] forward references from n, David Carlisle |
[xsl] catching the last node still , Guillaume Rousse | Date | Re: [xsl] catching the last node st, Dimitar Peikov |
Month |
Keywords