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

Re: [xsl] iterate over data on same line


Subject: Re: [xsl] iterate over data on same line
From: andrew welch <andrew.j.welch@xxxxxxxxx>
Date: Wed, 30 Nov 2005 11:54:12 +0000

> I have the following data in my xml:
>
> <parameter name="measType">
>                 <in/>
>                 <dataType>
>                     <long>
>                         <range>
>                             <min>24</min> <max>24</max>
>                             <min>26</min> <max>26</max>
>                             <min>28</min> <max>33</max>
>                             <min>44</min> <max>44</max>
>                             <min>900</min> <max>900</max>
>                         </range>
>                     </long>
>                 </dataType>
>             </parameter>
>
>
> How can I select each pair of min AND max? I need to iterate over both. Is
it possible?

Apply-templates to all the <min> elements:

<xsl:template match="range">
  <xsl:apply-templates select="min"/>
</xsl:template>

Then in the <min> matching template, apply-templates to the first
following-sibling <max>:

<xsl:template match="min">
  <xsl:value-of select="."/>
  <xsl:apply-templates select="following-sibling::max[1]"/>
</xsl:template>

<xsl:template match="max">
  <xsl:value-of select="."/>
</xsl:template>

You'll have to replace the value-of's with whatever output you need
for the values.

cheers
andrew


Current Thread