sort list node
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 2
- Joined: Fri Jun 11, 2004 1:56 pm
sort list node
hi,
i need to send as a param a sorted list of subnodes.
the xsl looks like this:
<xsl:for-each select="//branch[@level=$maxlevel - 1]">
<tr>
<xsl:for-each select="ancestor-or-self::*/shortdescription">
<td>
<xsl:value-of select="." />
</td>
</xsl:for-each>
<xsl:call-template name="mainfillTDfield">
<xsl:with-param name="nodelist" select="branch" />
<xsl:with-param name="pos" select="1" />
</xsl:call-template>
</tr>
</xsl:for-each>
what i want is to sort the nodelist by id of the last level branch:
and the corresponding xml is as follows:
<treedata xsi:noNamespaceSchemaLocation="C:\installaxiom\axiom_app\class\viewer.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<branch branchtype="exposure_level" level="1">
<shortdescription>Greater___than_500K</shortdescription>
<longdescription>Greater___than_500K</longdescription>
<id/>
<branch branchtype="app_book_name" level="2">
<shortdescription>CANADIAN ALBERTA GAS BOOK ALBERTA</shortdescription>
<longdescription>CANADIAN ALBERTA GAS BOOK ALBERTA</longdescription>
<id/>
<branch branchtype="book_app_code" level="3">
<shortdescription>C_GAS_ALTA</shortdescription>
<longdescription>C_GAS_ALTA</longdescription>
<id/>
<branch branchtype="book_name" level="4">
<shortdescription>ALBERTA</shortdescription>
<longdescription>ALBERTA</longdescription>
<id/>
<branch branchtype="trader_name" level="5">
<shortdescription>Jeff Peacock</shortdescription>
<longdescription>Jeff Peacock</longdescription>
<id>5</id>
<field fieldcode="declined_qty">106093901.0</field>
<field fieldcode="exposure_mtm_amt">0.0</field>
<field fieldcode="monthly_qty">106093901.0</field>
</branch>
<branch branchtype="trader_name" level="5">
<shortdescription>PEACOCK</shortdescription>
<longdescription>PEACOCK</longdescription>
<id>2</id>
<field fieldcode="declined_qty">20272157.0</field>
<field fieldcode="exposure_mtm_amt">0.0</field>
<field fieldcode="monthly_qty">20272157.0</field>
</branch>
.....
</branch>
......
</branch>
....
</branch>
......
</branch>
......
</treedata>
i tried to put the sort element in the for-each as follows:
<xsl:sort select="branch/id" data-type="number"/>
this doesn't work.
any ideas ?
thankx
miraodb
i need to send as a param a sorted list of subnodes.
the xsl looks like this:
<xsl:for-each select="//branch[@level=$maxlevel - 1]">
<tr>
<xsl:for-each select="ancestor-or-self::*/shortdescription">
<td>
<xsl:value-of select="." />
</td>
</xsl:for-each>
<xsl:call-template name="mainfillTDfield">
<xsl:with-param name="nodelist" select="branch" />
<xsl:with-param name="pos" select="1" />
</xsl:call-template>
</tr>
</xsl:for-each>
what i want is to sort the nodelist by id of the last level branch:
and the corresponding xml is as follows:
<treedata xsi:noNamespaceSchemaLocation="C:\installaxiom\axiom_app\class\viewer.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<branch branchtype="exposure_level" level="1">
<shortdescription>Greater___than_500K</shortdescription>
<longdescription>Greater___than_500K</longdescription>
<id/>
<branch branchtype="app_book_name" level="2">
<shortdescription>CANADIAN ALBERTA GAS BOOK ALBERTA</shortdescription>
<longdescription>CANADIAN ALBERTA GAS BOOK ALBERTA</longdescription>
<id/>
<branch branchtype="book_app_code" level="3">
<shortdescription>C_GAS_ALTA</shortdescription>
<longdescription>C_GAS_ALTA</longdescription>
<id/>
<branch branchtype="book_name" level="4">
<shortdescription>ALBERTA</shortdescription>
<longdescription>ALBERTA</longdescription>
<id/>
<branch branchtype="trader_name" level="5">
<shortdescription>Jeff Peacock</shortdescription>
<longdescription>Jeff Peacock</longdescription>
<id>5</id>
<field fieldcode="declined_qty">106093901.0</field>
<field fieldcode="exposure_mtm_amt">0.0</field>
<field fieldcode="monthly_qty">106093901.0</field>
</branch>
<branch branchtype="trader_name" level="5">
<shortdescription>PEACOCK</shortdescription>
<longdescription>PEACOCK</longdescription>
<id>2</id>
<field fieldcode="declined_qty">20272157.0</field>
<field fieldcode="exposure_mtm_amt">0.0</field>
<field fieldcode="monthly_qty">20272157.0</field>
</branch>
.....
</branch>
......
</branch>
....
</branch>
......
</branch>
......
</treedata>
i tried to put the sort element in the for-each as follows:
<xsl:sort select="branch/id" data-type="number"/>
this doesn't work.
any ideas ?
thankx
miraodb
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Hi,
What is not clear for you is the context node. You can use the XSLT Debugger from oXygen and step through transformations and look at the context node in each moment. When you have an xsl:for-each the context changes to each match of the xsl:for-each/@select. Therefore in your case the xsl:for-each selects branch elements so all you have to to is to use:
<xsl:sort data-type="number" select="id"/>
instead of
<xsl:sort data-type="number" select="branch/id"/>
The following code should present as output [2] [5] when applied on your input document:
Hope that helps,
George
What is not clear for you is the context node. You can use the XSLT Debugger from oXygen and step through transformations and look at the context node in each moment. When you have an xsl:for-each the context changes to each match of the xsl:for-each/@select. Therefore in your case the xsl:for-each selects branch elements so all you have to to is to use:
<xsl:sort data-type="number" select="id"/>
instead of
<xsl:sort data-type="number" select="branch/id"/>
The following code should present as output [2] [5] when applied on your input document:
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:for-each select="//branch[@level=5]">
<xsl:sort data-type="number" select="id"/>
[<xsl:value-of select="id"/>]
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
George
-
- Posts: 2
- Joined: Fri Jun 11, 2004 1:56 pm
found it
thankx for uor answer but i actually found another solution, it wasn't that easy as you because, we shouldn't forget that sort element can be nested only under for-each or apply-templates and i used recursion with call-template to generate the tree !
anyway, if u're interested i can post the code.
thank anyway.
miraodb
anyway, if u're interested i can post the code.
thank anyway.
miraodb

Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service