[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Getting max/min numbers out of nested structure


Subject: Re: [xsl] Getting max/min numbers out of nested structure
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Mon, 10 Jun 2013 17:43:40 +0200

Michele R Combs wrote:
Given this nested structure (hope it comes through legibly):

<a>
      <b>
           <box>1</box>
           <box>1</box>
      </b>
      <b>
           <box>1</box>
           <box>2</box>
           <c>
                <box>2</box>
                <box>2</box>
           </c>
      </b>
</a>
<a>
      <b>
           <box>3</box>
           <box>4</box>
           <c>
                <box>6</box>
                <box>6</box>
           </c>
           <box>5</box>
           <box>5</box>
      </b>
      <b>
           <box>5</box>
           <box>5</box>
      </b>
</a>

What is the easiest way to find the max/min box numbers in each <a>? That is, for the first <a> I want "1-2" and for the second <a> I want "3-6." FYI, in the real data, rather than stopping at three nested levels (a, b, c) it can potentially go up to 12 (!!). Normally I would simply grab the value from the first descendant and the value from the last descendant, but it turns out that sometimes the numbers aren't in order within the document tree (as shown in the second <a>) so that's not reliable enough.

<xsl:template match="a"> <xsl:variable name="max" select="max(.//box)"/> <xsl:variable name="min" select="min(.//box)"/> </xsl:template>


Current Thread