Subject: [xsl] maximum depth of nested tags needed for colspan From: "Andy Verbunt" <andy@xxxxxxxx> Date: Fri, 7 Nov 2003 20:47:04 +0100 |
Hi there, I wish somebody could help me with the problem I've been having for quite a few days now: I have this xml file: <a> <b> <question> <c/> <question> <d/> <question> <e/> </question> </question> </question> </b> <f> <question> <question> <question> <question> <g/> </question> </question> </question> </question> </f> </a> I never checked this xml, but I guess you catch my drift... The question-tags are relevant, but nevertheless, I put some other tags in and around the question tags to show you that there's more than one type of tag. I'd like to make an xslt that can transform this xml to html, actually to a table. I need to indent questions which are deeper in the hierarchy. Basically this means that I need to transform the a-tag to a table tag. I need the maximum depth of the question tags as a colspan attribute for the td-tag in order to get the indentation right. In this case that would be: 4, since <f> contains 4 nested question tags while <b> contains only 3. I found some similar examples in 'XSLT 2nd edition' from Michael Kay, which were solved using recursion, but these were not about nested tags. He uses some trick with two params: first and max-of-rest, but the tags he uses are all on the same 'level', while my question-tags are nested. I added that code at the end of my message. Adding a level attribute with the current depth to the question tag is easy using count(ancestor::question) but I cannot find out how to add the 4 (in this case) to the first tag. Please help... Kind regards, Andy. <xsl:template name="max"> <xsl:param name="list"/> <xsl:choose> <xsl:when test="$list"> <xsl:variable name="first" select="count($list[1]/LINE)"/> <xsl:variable name="max-of-rest"> <xsl:call-template name="max"> <xsl:with-param name="list" select="$list[position()!=1]"/> </xsl:call-template> </xsl:variable> <xsl:choose> <xsl:when test="$first > $max-of-rest"> <xsl:value-of select="$first"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$max-of-rest"/> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise>0</xsl:otherwise> </xsl:choose> </xsl:template> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Problem with Muenchian gr, cknell | Thread | Re: [xsl] maximum depth of nested t, Wendell Piez |
Re: [xsl] Re: Filtering with multip, Dongling Ding | Date | [xsl] Lookup without document('') f, David Carver |
Month |