Developer forum

Forum » Templates » Datalist - Sorting by Zipcode, show city name

Datalist - Sorting by Zipcode, show city name


Reply

Hi,

I need to sort cities by zipcode-range. Usually I would be able to do this, but as it is coming from Datalists, it seems to loop through the tags in a way that makes me unable to draw both zipcode and cityname out.

Here's my XSLT:

...

<xsl:key name="items-by-by" match="item" use="Row.Value" />    
<xsl:template match="loop[@name='Row']">

<xsl:param name="pnrfr">

<xsl:choose>

<xsl:when test="not(//Template/Server.Request.pnrfr)">

<xsl:text>nej</xsl:text>

</xsl:when>

<xsl:otherwise>

<xsl:value-of select="//Template/Server.Request.pnrfr" />

</xsl:otherwise>

</xsl:choose>

</xsl:param> 

<xsl:param name="pnrto">

<xsl:choose>

<xsl:when test="not(//Template/Server.Request.pnrto)">

<xsl:text>nej</xsl:text>

</xsl:when>

<xsl:otherwise>

<xsl:value-of select="//Template/Server.Request.pnrto" />

</xsl:otherwise>

</xsl:choose>

</xsl:param>

<xsl:for-each select="item[count(. | key('items-by-by', Row.Value)[1]) = 1]">

<xsl:sort select="Row.Value" />

<xsl:choose>

<xsl:when test="$pnrfr = 'nej'">

<xsl:if test="Row.ColumnName = 'By'">

     <br /><a>

<xsl:attribute name="href">Default.aspx?ID=639&amp;sby=<xsl:value-of select="Row.Value" disable-output-escaping="yes" /></xsl:attribute>

<xsl:value-of select="Row.Value" disable-output-escaping="yes" />

</a>

</xsl:if>

</xsl:when>

<xsl:otherwise>

<xsl:variable name="by">

<xsl:if test="Row.ColumnName = 'By'">

<xsl:value-of select="Row.Value" disable-output-escaping="yes" />

</xsl:if>

</xsl:variable>

<xsl:variable name="pnr">

<xsl:if test="Row.ColumnName = 'Postnummer'">

<xsl:value-of select="Row.Value" disable-output-escaping="yes" />

</xsl:if> 

</xsl:variable> 

 


<xsl:if test="Row.ColumnName = 'By'">

         <!-- <xsl:if test="$pnr > $pnrto and $pnrfr > $pnr"> -->   

     <br /><a>

     <xsl:attribute name="href">Default.aspx?ID=639&amp;sby=<xsl:value-of select="$by" disable-output-escaping="yes" /></xsl:attribute>

     <xsl:value-of select="$by" disable-output-escaping="yes" />

     </a>

     <!-- </xsl:if> --> 

     </xsl:if>

    </xsl:otherwise>

    </xsl:choose>

   </xsl:for-each>

 </xsl:template>    


and here is the XML:
<loop name="Row">
<item>
<Row.ColumnName>By</Row.ColumnName>
<Row.Value>Testby</Row.Value>
<Row.Count>0</Row.Count>
<Column.Count>0</Column.Count>
</item>
...
</loop>

- I am pretty lost, and I've tried "everything". I hope you can help me!


Replies

 

You must be logged in to post in the forum