xsl-list
[Top] [All Lists]

RE: how to sort by different attributes in a table

2004-08-30 15:24:24
Attributes don't have any predictable order, so it doesn't make any sense to
ask for elements to be sorted on "their third attribute".

It's possible that select="@*[number($Sort)]" will work for you, but it's
rather implementation-dependent.

Michael Kay 

-----Original Message-----
From: Shen, Ching [mailto:Shenc(_at_)cboe(_dot_)com] 
Sent: 30 August 2004 22:42
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] how to sort by different attributes in a table


Michael:
Thanks for the suggestion. Unfortunately, you change didn't work.
Here Sort=1,2,3.... which is column position number
But @[local-name()] = A, B, C, ... which is column name

Any further suggest?


-----Original Message-----
From: Michael Kay [mailto:mhk(_at_)mhk(_dot_)me(_dot_)uk]
Sent: Monday, August 30, 2004 4:06 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] how to sort by different attributes in a table


This is a FAQ.

Use <xsl:sort select="@*[local-name() = $Sort]"/>

The reason your attempt doesn't work is that a sort key such 
as $Sort that
doesn't depend on the context node will have the same value 
for each of the
nodes in the node-set being sorted. The system can't guess 
that you want to
treat the value of this variable, e.g. "HOSTNAME", as an 
XPath expression.

Michael Kay

 

-----Original Message-----
From: Shen, Ching [mailto:Shenc(_at_)cboe(_dot_)com] 
Sent: 30 August 2004 20:54
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] how to sort by different attributes in a table


I have a xml file which looks like
<Rows>
  <Row>
    <Columns A=3D"HOSTNAME" B=3D"IPADDRESS" C=3D"BRAND/MODEL" />
  </Row>
 <Row>
    <Columns A=3D"AA" B=3D"23" C=3D"ibm" />
  </Row>
......
</Rows>


I have all attributes list in a table as columns and I need a 
xsl syntax =
which will allow me to sort by selected attribute, when they click =
attribute header,=20

i. e. when user click 2nd column header, all xml file will 
sorted by =
<xsl:sort select=3D"*/@B" />

The following syntax failed to work and I run out clue. 
Here  header =
link set to Sort=3D{position()}=20

    <xsl:apply-templates select=3D"*/*">
                <xsl:sort select=3D"*/@Columns[$Sort]" />
    </xsl:apply-templates>

Does anybody have done this before and can help me out with 
right syntax?
Your suggestions will be greatly appreciated


Thank you!

Ching 


--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--




--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--


--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--