SharkTooth
Programmer
I can't seem to get the <xsl:sort select element to work. I don't get an error it just doesn't sort. This is my first experence with XSLT so I'm guessing that I'm not using the <xsl:sort element correctly. Would you guys please take a look at what I'm doing below with the sort element? Everything else works fine, I just need to get the sort going.
I have an xml file formatted like so...
<?xml version="1.0" encoding="iso-8859-1"?>
<jobwatch>
<region desc="Areas of Pennsylvania, New Jersey and Delaware" id="N01" coords="368,155,363,131,399,123,407,128,407,138,416,142,421,160,407,161,401,148">
<thisAd>
<client>The Client Name 1</client>
<adCode>121212</adCode>
<magName>PXX1</magName>
<issueDate>02/05/2000</issueDate>
<imagePath>ads/121212.jpg</imagePath>
</thisAd>
<thisAd>
<client>The Client Name 2</client>
<adCode>232323</adCode>
<magName>PXX1</magName>
<issueDate>02/05/2001</issueDate>
<imagePath>ads/121214.jpg</imagePath>
</thisAd>
NEXT Region ...
This is my XSLT...
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
<xsl:strip-space elements="*"/>
<xslutput method="html" indent="no"/>
<xsl:variable name="COLS" select="2"/>
<xsl:variable name="ROWS" select="ceiling(count(/jobwatch/region[@id='N01']/thisAd) div $COLS)"/>
<xsl:variable name="CELLS" select="$COLS * $ROWS"/>
<xsl:template match="/jobwatch/region[@id='N01']">
<table width="100%" border="1" cellpadding="5">
<tr>
<xsl:call-template name="Column"/>
</tr>
</table>
</xsl:template>
<xsl:template match="/jobwatch/region[@id!='N01']">
</xsl:template>
<xsl:template name="Column">
<xslaram name="NEXT" select="1"/>
<xsl:if test="$NEXT <= $CELLS">
<xsl:variable name="POS" select="(($NEXT - 1) mod $COLS) * $ROWS + ceiling($NEXT div $COLS)"/>
<td valign="top" nowrap="true">
<xsl:choose>
<xsl:when test="thisAd[position() = $POS]">
<xsl:apply-templates select="thisAd[position() = $POS]/client">
<xsl:sort select="thisAd/client"/>
</xsl:apply-templates>
</xsl:when>
<xsltherwise>
<p></p>
</xsltherwise>
</xsl:choose>
</td>
<xsl:if test="$NEXT mod $COLS = 0 and $NEXT != $CELLS">
<xsl:text disable-output-escaping="yes"></tr><tr></xsl:text>
</xsl:if>
<xsl:call-template name="Column">
<xsl:with-param name="NEXT" select="number($NEXT) + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="thisAd/client">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
Thanks for you help!
I have an xml file formatted like so...
<?xml version="1.0" encoding="iso-8859-1"?>
<jobwatch>
<region desc="Areas of Pennsylvania, New Jersey and Delaware" id="N01" coords="368,155,363,131,399,123,407,128,407,138,416,142,421,160,407,161,401,148">
<thisAd>
<client>The Client Name 1</client>
<adCode>121212</adCode>
<magName>PXX1</magName>
<issueDate>02/05/2000</issueDate>
<imagePath>ads/121212.jpg</imagePath>
</thisAd>
<thisAd>
<client>The Client Name 2</client>
<adCode>232323</adCode>
<magName>PXX1</magName>
<issueDate>02/05/2001</issueDate>
<imagePath>ads/121214.jpg</imagePath>
</thisAd>
NEXT Region ...
This is my XSLT...
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
<xsl:strip-space elements="*"/>
<xslutput method="html" indent="no"/>
<xsl:variable name="COLS" select="2"/>
<xsl:variable name="ROWS" select="ceiling(count(/jobwatch/region[@id='N01']/thisAd) div $COLS)"/>
<xsl:variable name="CELLS" select="$COLS * $ROWS"/>
<xsl:template match="/jobwatch/region[@id='N01']">
<table width="100%" border="1" cellpadding="5">
<tr>
<xsl:call-template name="Column"/>
</tr>
</table>
</xsl:template>
<xsl:template match="/jobwatch/region[@id!='N01']">
</xsl:template>
<xsl:template name="Column">
<xslaram name="NEXT" select="1"/>
<xsl:if test="$NEXT <= $CELLS">
<xsl:variable name="POS" select="(($NEXT - 1) mod $COLS) * $ROWS + ceiling($NEXT div $COLS)"/>
<td valign="top" nowrap="true">
<xsl:choose>
<xsl:when test="thisAd[position() = $POS]">
<xsl:apply-templates select="thisAd[position() = $POS]/client">
<xsl:sort select="thisAd/client"/>
</xsl:apply-templates>
</xsl:when>
<xsltherwise>
<p></p>
</xsltherwise>
</xsl:choose>
</td>
<xsl:if test="$NEXT mod $COLS = 0 and $NEXT != $CELLS">
<xsl:text disable-output-escaping="yes"></tr><tr></xsl:text>
</xsl:if>
<xsl:call-template name="Column">
<xsl:with-param name="NEXT" select="number($NEXT) + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="thisAd/client">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
Thanks for you help!