M
Michael Hill
I have a section of a stylesheet (below) I am trying to configure.
The part I am having trouble with is the when test.
I have a series of pulldowns that I can select from, some are text and some
are number.
If the sort field is "field1" then I need to sort by number, but if "field2"
I need to sort by text. There are other fields as well.
Do I have to do a <xsl:when test=""> <snip> </xsl:test> for each field or
can't I just do sommething like:
<xsl:when test="$sortfield contains['field1','field3','field5','field7']>
<snip going to sort by number>
</xsl:when>
<xsl:when test="$sortfield contains['field2','field2','field4','field6']>
<snip going to sort by text>
</xsl:when>
Then I only have 2 when tests and not 8.
Thanks,
Mike
****** xslt segment below ******
<xslutput method="xml"/>
<xslaram name="sortorder" select="'descending'"/>
<xslaram name="sortfield" />
<xsl:template match="/">
<root>
<xsl:choose>
<xsl:when test="$sortfield='field1'>
<xsl:for-each select="root/data" >
<xsl:sort select="*[name(.)=$sortfield]" order="{$sortorder}"
data-type="number"/>
<data><xsl:apply-templates select="*"/></data>
</xsl:for-each>
</xsl:when>
<xsl:when test="$sortfield='field2'>
<xsl:for-each select="root/data" >
<xsl:sort select="*[name(.)=$sortfield]" order="{$sortorder}"
data-type="number"/>
<data><xsl:apply-templates select="*"/></data>
</xsl:for-each>
</xsl:when>
</xsl:choose>
</root>
</xsl:template>
The part I am having trouble with is the when test.
I have a series of pulldowns that I can select from, some are text and some
are number.
If the sort field is "field1" then I need to sort by number, but if "field2"
I need to sort by text. There are other fields as well.
Do I have to do a <xsl:when test=""> <snip> </xsl:test> for each field or
can't I just do sommething like:
<xsl:when test="$sortfield contains['field1','field3','field5','field7']>
<snip going to sort by number>
</xsl:when>
<xsl:when test="$sortfield contains['field2','field2','field4','field6']>
<snip going to sort by text>
</xsl:when>
Then I only have 2 when tests and not 8.
Thanks,
Mike
****** xslt segment below ******
<xslutput method="xml"/>
<xslaram name="sortorder" select="'descending'"/>
<xslaram name="sortfield" />
<xsl:template match="/">
<root>
<xsl:choose>
<xsl:when test="$sortfield='field1'>
<xsl:for-each select="root/data" >
<xsl:sort select="*[name(.)=$sortfield]" order="{$sortorder}"
data-type="number"/>
<data><xsl:apply-templates select="*"/></data>
</xsl:for-each>
</xsl:when>
<xsl:when test="$sortfield='field2'>
<xsl:for-each select="root/data" >
<xsl:sort select="*[name(.)=$sortfield]" order="{$sortorder}"
data-type="number"/>
<data><xsl:apply-templates select="*"/></data>
</xsl:for-each>
</xsl:when>
</xsl:choose>
</root>
</xsl:template>