[xsl] Re: Re: recursive template grabbing nested elements...

Subject: [xsl] Re: Re: recursive template grabbing nested elements...
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Sun, 15 Jul 2001 02:29:52 -0700 (PDT)
Jeni Tennison wrote:


> I should think Dimitre will show you an alternative that is not as
> closely coupled with your source XML, using one of his generic
> templates.

As Jeni suggested, I'm including finding the deepest "tab" element by using the
generic max() template.

The main thing to note is, you only have to specify the "comparison template" and
this gives you automatically the whole solution -- no need to re-program for the
N-th time your max() template, no possibility at all to make any mistakes as this
additional coding simply does not exist any more.

This is an almost mechanical, straightforward activity, taking only a couple of

Your source xml (genericMath.minmax.data.2.xml):
  <tab state="on" id="1.1">
    <tab state="off" id="1.1.1">

    <tab state="on" id="1.1.2">

  <tab state="off" id="1.2">

The stylesheet (genericMath.minmax.2.xsl):
<xsl:stylesheet version="1.0"


  <xsl:variable name="gt-node" select="document('')//gt-deeper:*"/>

 <xsl:output omit-xml-declaration="yes"/>

 <!-- You can download the following file at 
      http://www.vbxml.com/downloads/default.asp?id=v2001611171627 -->

 <xsl:include href="genericMath.minmax.template.xsl"/>
 <xsl:variable name="nodes" select="//tab"/>

<xsl:template match="/">
<xsl:variable name="vMax1">
 <xsl:call-template name="pMax">
   <xsl:with-param name="nodes" select="$nodes"/>
   <xsl:with-param name="start" select="1"/>
   <xsl:with-param name="end" select="count($nodes)"/>
   <xsl:with-param name="greaterTemplateUID" select="$gt-node"/>

<xsl:value-of select="concat('Max1: nodes[',$vMax1, '] = ',
$nodes[position()=$vMax1]/@id )"/>

<xsl:template match="*[namespace-uri() = 'gt-deeper']">
	<xsl:param name="n1" select="/.."/>
	<xsl:param name="n2" select="/.."/>

    <xsl:value-of select="count($n1/ancestor::*) > count($n2/ancestor::*)"/>


Max1: nodes[2] = 1.1.1

Dimitre Novatchev.

Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread