[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

maximum depth of nested tags needed for colspan

Subject: maximum depth of nested tags needed for colspan
From: "Andy Verbunt" <andy@xxxxxxxx>
Date: Fri, 7 Nov 2003 20:47:04 +0100
question tags
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 &gt;
$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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.