# XSL for-each/when problem

**URL:** <https://forum.kirupa.com/t/xsl-for-each-when-problem/255738>\
**Category:** web dev\
**Created:** [March 26, 2008, 2:05pm UTC](https://forum.kirupa.com/t/xsl-for-each-when-problem/255738 "2008-03-26T14:05:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grofit](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/grofit/32/4058_2.png) [@Grofit](https://forum.kirupa.com/u/Grofit)\
**Post date:** [March 26, 2008, 2:05pm UTC](https://forum.kirupa.com/t/xsl-for-each-when-problem/255738/1 "2008-03-26T14:05:46Z")

</div>

Hey,

Not sure if much XSL stuff goes on in here, but im currently having a problem and the debug information is as useless as a a chocolate fireguard.

Im currently just trying to do something simple…

Read in an XML file, style it with an XSL file, then display it in a div…  
All works fine, but as soon as i try to put in sorting logic it just all falls apart and i dont have a clue why…

```auto

<xsl:param name="sort_type"/>

    
<xsl:template match="/">

<table cellspacing="0" cellpadding="0" border="0" >
  <tr>
    <th>Address 1</th>
    <th>Address 2</th>
  </tr>
<xsl:for-each select="people/person">
  <xsl:choose>
    <xsl:when test="contains($sort_type, 'address_1')">
      <xsl:sort select="address_1" order="descending" data-type="text" />        
    </xsl:when>
    <xsl:otherwise>
      <xsl:sort select="id" order="descending" data-type="number" />
    </xsl:otherwise>
  </xsl:choose>
  <tr>
    <td><xsl:value-of select="address_1" /></td>
    <td><xsl:value-of select="address_2" /></td>
  </tr>
</xsl:for-each>
</table> 

    </xsl:template>

```

There is also stuff for the stylesheet defines but i thought i would only bother showing the core part. Anyway as you can see i do the for-each, then sort it based on the $sort\_type, the sort\_type is set via javascript externally, but i know it works as if i display it via XSL without the sorting logic it displays the correct contents. The default XML contains people, which contains many persons, all having address 1,2 and an ID but i only want to display the addresses.

The error i keep getting basically says there is an exception when processing the XSL, if i take out the sorting logic it works fine, so am i doing something wrong, im basing most of my stuff from the w3schools and other various tutorials online…

ANY help would be great!
