xsl:sort when mix of numbers and null values

xsl:sort when mix of numbers and null values

Post by Red Ogd » Thu, 19 Jun 2003 23:05:21



Hello


Please can anyone suggest the most efficient way to to order so that a
value 1 comes first followed by any other numbers in ascending order
and all nulls follow that?

I have tried creating a variable where the null values are represented
by the character 'N' but I seem to be having problems with the scope
as my processor complains that the variable $keyseq has not been
defined.

Any suggestions would be most welcome..
Thanks

Redge.

<xsl:for-each select="COLUMN">
 <xsl:variable name="keyseq" >
<xsl:choose>


        <xsl:otherwise><xsl:value-of select="'N'" /></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:sort select="$keyseq" order="ascending" ></xsl:sort>

 
 
 

xsl:sort when mix of numbers and null values

Post by Oleg Tkachenk » Fri, 20 Jun 2003 00:35:59



> I want to sort according to a primary key sequence number attribute

> Please can anyone suggest the most efficient way to to order so that a
> value 1 comes first followed by any other numbers in ascending order
> and all nulls follow that?


with null value.



...
</xsl:for-each>


...
</xsl:for-each>
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

 
 
 

xsl:sort when mix of numbers and null values

Post by Colin Mackenzi » Thu, 19 Jun 2003 22:54:26


cant do it with variables as you say due to scope, how about doing all the
numbers first tthen all the nulls (or am I missing something)
ie.

<xsl:for-each select="COLUMN">
    <xsl:sort select="$keyseq" order="ascending" ></xsl:sort>


        only output non nulls
    </xsl:if>
</xsl:for-each>
<xsl:for-each select="COLUMN">
    <xsl:sort select="$keyseq" order="ascending" ></xsl:sort>


        only output nulls
    </xsl:if>
</xsl:for-each>

or


Colin


> Hello

> I want to sort according to a primary key sequence number attribute

> Please can anyone suggest the most efficient way to to order so that a
> value 1 comes first followed by any other numbers in ascending order
> and all nulls follow that?

> I have tried creating a variable where the null values are represented
> by the character 'N' but I seem to be having problems with the scope
> as my processor complains that the variable $keyseq has not been
> defined.

> Any suggestions would be most welcome..
> Thanks

> Redge.

> <xsl:for-each select="COLUMN">
>  <xsl:variable name="keyseq" >
> <xsl:choose>


> <xsl:otherwise><xsl:value-of select="'N'" /></xsl:otherwise>
> </xsl:choose>
> </xsl:variable>
> <xsl:sort select="$keyseq" order="ascending" ></xsl:sort>


 
 
 

xsl:sort when mix of numbers and null values

Post by Red Ogd » Fri, 20 Jun 2003 06:47:44


Thank you both - it seems obvious now you mention it.

Redge

 
 
 

xsl:sort when mix of numbers and null values

Post by Red Ogd » Fri, 20 Jun 2003 17:01:17


The problem with this approach is that my xsl:for-each actually
contains a lot more elements than the honed-down example I sent.  This
means that I would have to repeat a big block of code with only the
for-each predicate changing.  Is this the only solution?

Thanks
Redge.

 
 
 

xsl:sort when mix of numbers and null values

Post by Oleg Tkachenk » Fri, 20 Jun 2003 18:12:02



> The problem with this approach is that my xsl:for-each actually
> contains a lot more elements than the honed-down example I sent.  This
> means that I would have to repeat a big block of code with only the
> for-each predicate changing.  Is this the only solution?

Use named template to modularize your code.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel
 
 
 

xsl:sort when mix of numbers and null values

Post by Colin Mackenzi » Fri, 20 Jun 2003 16:31:21


use call-template within the for-eahc for the re-usable code

<xsl:for-each select="this">
    <xsl:call-template name="doStuff">
</xsl:for-each>

<xsl:for-each select="that">
    <xsl:call-template name="doStuff">
</xsl:for-each>

possibly with a param saying we are doing this or that if you need
conditional processing inside

Colin


Quote:> The problem with this approach is that my xsl:for-each actually
> contains a lot more elements than the honed-down example I sent.  This
> means that I would have to repeat a big block of code with only the
> for-each predicate changing.  Is this the only solution?

> Thanks
> Redge.

 
 
 

xsl:sort when mix of numbers and null values

Post by Colin Mackenzi » Fri, 20 Jun 2003 16:45:06


or even replace the for-eahc with an apply-tempaltes (I never have sorted
using apply templates but the doc says it can be done) i.e.

<xsl:for-each select="COLUMN">
    <xsl:sort select="$keyseq" order="ascending" ></xsl:sort>


        only output non nulls
    </xsl:if>
</xsl:for-each>
<xsl:for-each select="COLUMN">
    <xsl:sort select="$keyseq" order="ascending" ></xsl:sort>


        only output nulls
    </xsl:if>
</xsl:for-each>

or



</xsl:apply-templates>



</xsl:apply-templates>

<xsl:template match="COLUMN">
    do stuff....
<xsl:template>

Colin


> use call-template within the for-eahc for the re-usable code

> <xsl:for-each select="this">
>     <xsl:call-template name="doStuff">
> </xsl:for-each>

> <xsl:for-each select="that">
>     <xsl:call-template name="doStuff">
> </xsl:for-each>

> possibly with a param saying we are doing this or that if you need
> conditional processing inside

> Colin



> > The problem with this approach is that my xsl:for-each actually
> > contains a lot more elements than the honed-down example I sent.  This
> > means that I would have to repeat a big block of code with only the
> > for-each predicate changing.  Is this the only solution?

> > Thanks
> > Redge.

 
 
 

1. ><xsl:value-of select="(number(firstNum) - number(thirdNum))div 2 "/>

Hi Everybody!

I am working with ie5.5 including the new xmlsdk. i have been using the
xalan xml parser up do now , but need to use the msxml parser for better
performance. my problem is to convert my current stylesheet to a format
that the msxml parser understands

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

 which is supported by a different parser. What I want to do is use the
values of two different nodes to perform a calculation. I have included
code, but I am having difficulties to get ie5.x to parse the code using
the namespace:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" version="1.0">

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

"xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                                            version="1.0">

 Please advice me how I should go about to achieve a similar result with
the ie5.x parser.

 Thank you.
Bernhard

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<!-- <xsl:template match="/">
<HTML><BODY>
    <TABLE>
        <xsl:for-each select="number">
        <TR>
            <TD><xsl:value-of select="firstNum"/></TD>
            <TD><xsl:value-of select="thirdNum"/></TD>
            <TD><xsl:value-of select="(number(firstNum) -
number(thirdNum))div 2"/></TD>
        </TR>
        </xsl:for-each>
    </TABLE>
</BODY></HTML>
</xsl:template>
</xsl:stylesheet>

2. Alarm sensors on casement windows

3. Can Anyone Help: XSL& Data Islands returning null for record number

4. Simple hyperlink question

5. Display value e.g. "Unknown" for a Null valued element

6. Don't know MSN Server Address

7. How to sort using xsl:sort on attribute value?

8. Copyng Audio CD's Problems

9. null values in XSL patterns

10. Null value in xsl

11. XSL/XPATH and sorting abs(number)

12. Sorting Numbers using XSL.

13. Number() sorting in XSL