Sorting table data by column

Questions about XML that are not covered by the other forums should go here.
nate
Posts: 3
Joined: Tue Apr 08, 2008 4:31 pm

Sorting table data by column

Post by nate »

Hello,

I seem to have a little program with table sorting:
Let's say I have a table with 2 columns: ClientName and Details. So far, data in the table is unsorted, while I'd love them to be sorted by Client alphabetically. Like, first would go Mr. Adams with his description, then Mr. Bartleby with his, etc.
I tried to switch to the grid view, right-click the column and select "sort ascending/ descending" - but that does not seem to work in the right way :(

All I could manage - was to have data in separate rows sorted, while changes should have been applied to the whole table.

Please help!

P.S. all this applies to DocBook documentation - if that helps
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Sorting table data by column

Post by sorin_ristache »

Hello,

Do you mean you want to sort the rows of a table in a DocBook document by modifying the DocBook XML document? The action Sort ascending available on the popup menu should do the trick when you right click on the column with the person names and select the sorting action. If it does not work for you please post a small sample XML document that contains the table that you want to sort alphabetically.


Regards,
Sorin
nate
Posts: 3
Joined: Tue Apr 08, 2008 4:31 pm

Re: Sorting table data by column

Post by nate »

Hello, thanks for the reply,

the code chunk can be like this:

Code: Select all

<informaltable>
<tgroup cols="2">
<colspec colnum="2" colname="col2" colwidth="*"/>
<colspec colnum="1" colname="col1" colwidth="*"/>

<thead>
<row>
<entry colname="col1">
<para>Client</para>
</entry>
<entry colname="col2">
<para>Description</para>
</entry>
</row>
</thead>

<tbody>
<row>
<entry colname="col1">
<para>Bartleby</para>
</entry>
<entry colname="col2">
<para>some description text for Bart</para>
</entry>
</row>
<row>
<entry colname="col1">
<para>Adams</para>
</entry>
<entry colname="col2">
<para>some description text for Adams</para>
</entry>
</row>
<row>
<entry>
<para>Collins</para>
</entry>
<entry>
<para>some description for Collins</para>
</entry>
</row>
<row>
<entry>
<para>Aarons</para>
</entry>
<entry>
<para>some description text for Aarons</para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
Wished result is a table sorted in the following way:

Code: Select all


Client		Description

Aarons some description text for Aarons
Adams some description text for Adams
Bartleby some description text for Bart
Collins some description for Collins
Thanks!
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Sorting table data by column

Post by sorin_ristache »

Hello,

The entry elements containing the person names are not sibling elements, that is they have different parent elements instead of a common parent element. That means they cannot displayed as a table in the Grid mode of the XML editor so they cannot be sorted with an action Sort ascending. You have to write and apply an XSLT stylesheet to your DocBook XML document which sorts the row elements of the informaltable based on the value of the entry element with the person name:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:db="http://docbook.org/ns/docbook">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="db:tbody">
<xsl:copy>
<xsl:apply-templates select="db:row">
<xsl:sort select="db:entry[1]"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Regards,
Sorin
nate
Posts: 3
Joined: Tue Apr 08, 2008 4:31 pm

Re: Sorting table data by column

Post by nate »

Thanks!
george_amazon
Posts: 2
Joined: Wed Oct 08, 2008 5:27 pm

Re: Sorting table data by column

Post by george_amazon »

So, there's no native table sorting mechanism in oXygen 9? Help talks about an A->Z icon, which I can't find--nothing when you right click on a table column.
tavy
Posts: 365
Joined: Thu Jul 01, 2004 12:29 pm

Re: Sorting table data by column

Post by tavy »

george_amazon wrote:So, there's no native table sorting mechanism in oXygen 9? Help talks about an A->Z icon, which I can't find--nothing when you right click on a table column.
No, there is no table sorting in Author mode in v9. Only the Grid mode has sorting, but that does not help you with tables. I'm guessing that's what you found in the Help.
However table sorting would be a very useful feature, so we added it to our bug tracking tool and we will probably implement it in a future version.

Regards,
Adrian Buza
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
george_amazon
Posts: 2
Joined: Wed Oct 08, 2008 5:27 pm

Re: Sorting table data by column

Post by george_amazon »

Great, Adrian. Thanks!

Only other suggestion is to revise the Help. It's not always very oriented toward the wysiwyg version of oXygen.
alexanderthelange
Posts: 1
Joined: Thu Sep 06, 2012 11:54 pm

Re: Sorting table data by column

Post by alexanderthelange »

In 2008, Adrian Buza wrote:
> we will probably implement it in a future version

Hi Adrian or other support folks,

It's 2012 now. Any news if this sort-by-column feature is on the roadmap?

Thanks!
Alex
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Sorting table data by column

Post by adrian »

Hello Alex,

This was rather difficult to implement at that time (the Author mode had just been introduced in v9.0/2008), so it got pushed further back.

This feature request is now scheduled for v14.2, but it could still be pushed back. I've added your comment and increased its priority, so hopefully it will stick with v14.2.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply