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

Subject: Re: [xsl] Getting max/min numbers out of nested structure
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 10 Jun 2013 11:42:46 -0400
At 2013-06-10 15:35 +0000, Michele R Combs wrote:
Given this nested structure (hope it comes through legibly):
...
What is the easiest way to find the max/min box numbers in each <a>?

The easiest is to use XSLT 2 as shown below. I hope this helps.


. . . . . . Ken

t:\ftemp>type michele.xml
<?xml version="1.0" encoding="UTF-8"?>
<test>
  <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>
</test>

t:\ftemp>xslt2 michele.xml michele.xsl
1 - 2
3 - 6

t:\ftemp>type michele.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="2.0">

<xsl:output method="text"/>

<xsl:template match="/">
  <xsl:for-each select="test/a">
    <xsl:value-of select="min(.//box),'-',max(.//box)"/>
    <xsl:text>&#xa;</xsl:text>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>
t:\ftemp>



--
Contact us for world-wide XML consulting and instructor-led training |
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm |
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/s/ |
G. Ken Holman                   mailto:gkholman@xxxxxxxxxxxxxxxxxxxx |
Google+ profile: https://plus.google.com/116832879756988317389/about |
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal |

Current Thread