I'm very new to xslt.
I have listed both the xml source document and the xslt style sheet below.
I don't really understand when the sorting is performed in this code snippet.
<xsl:apply-templates select="/Objects/Object" >
<xsl:sort select="@name" order="ascending" />
</xsl:apply-templates>
What I do know is that each time a node equal to Object is found from this location path select="/Objects/Object"
the xsl:template is called with the context node equal to Object
Xml source document
*****************
<?xml version="1.0" encoding="utf-8" ?>
In your XSLT, at the sort node you are using "order=Ascending/Descending" attribute, which ordered the selected value in the specified format. you can check the things by changing "order" values either to Ascending/Descending in the following
statement:
<xsl:sort select="@name" order="ascending" />
Hope it helps..
Please "Mark As Answer;", if this Post helps you.
Visit My Blog
I still haven't got any answer on my question.
Is the sort on all the node in the node-set done only once and that is when
the location path finds all the Object that is child to the Objects.
Tojo
Member
68 Points
212 Posts
I don't understand when the sort is done in this code
Feb 28, 2012 12:17 PM|LINK
Hello!
I'm very new to xslt.
I have listed both the xml source document and the xslt style sheet below.
I don't really understand when the sorting is performed in this code snippet.
<xsl:apply-templates select="/Objects/Object" >
<xsl:sort select="@name" order="ascending" />
</xsl:apply-templates>
What I do know is that each time a node equal to Object is found from this location path select="/Objects/Object"
the xsl:template is called with the context node equal to Object
Xml source document
*****************
<?xml version="1.0" encoding="utf-8" ?>
<Objects>
<Object name="CCC">
<Characterictic id="1">Hard</Characterictic>
<Characterictic id="2">Shiny</Characterictic>
<Characterictic id="3">Has 4 wheels</Characterictic>
<Characterictic id="4">Internal Combustion Engine</Characterictic>
<Characterictic id="5">Fast</Characterictic>
</Object>
<Object name="DDD">
<Characterictic id="1">Fruit</Characterictic>
<Characterictic id="2">Juicy</Characterictic>
<Characterictic id="3">Dimpled skin</Characterictic>
<Characterictic id="4">Citrus</Characterictic>
</Object>
<Object name="AAA">
<Characterictic id="1">Tall</Characterictic>
<Characterictic id="2">Four legs</Characterictic>
<Characterictic id="3">Big spots</Characterictic>
<Characterictic id="4">Mammal</Characterictic>
</Object>
<Object name="BBB">
<Characterictic id="1">Crisp</Characterictic>
<Characterictic id="2">Savoury</Characterictic>
<Characterictic id="3">Off white</Characterictic>
<Characterictic id="4">Edible</Characterictic>
</Object>
</Objects>
Xslt style sheet
*************
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/" >
<html>
<head>
<title>Object Characterictics</title>
</head>
<body>
<xsl:apply-templates select="/Objects/Object" >
<xsl:sort select="@name" order="ascending" />
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="Object">
<h3>Characteristics of <xsl:value-of select="@name" /></h3>
<ul>
<xsl:for-each select="Characterictic">
<xsl:sort select="." order="descending" />
<li><xsl:value-of select="." /></li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
//Tony
kuber.manral
Contributor
3051 Points
714 Posts
Re: I don't understand when the sort is done in this code
Feb 28, 2012 12:25 PM|LINK
Hi Tojo,
In your XSLT, at the sort node you are using "order=Ascending/Descending" attribute, which ordered the selected value in the specified format. you can check the things by changing "order" values either to Ascending/Descending in the following statement:
<xsl:sort select="@name" order="ascending" />
Hope it helps..
Visit My Blog
Tojo
Member
68 Points
212 Posts
Re: I don't understand when the sort is done in this code
Feb 28, 2012 01:55 PM|LINK
I still haven't got any answer on my question.
Is the sort on all the node in the node-set done only once and that is when
the location path finds all the Object that is child to the Objects.
<xsl:apply-templates select="/Objects/Object" >
<xsl:sort select="@name" order="ascending" />
</xsl:apply-templates>
//Tony
kuber.manral
Contributor
3051 Points
714 Posts
Re: I don't understand when the sort is done in this code
Feb 28, 2012 03:56 PM|LINK
Hi Tojo,
while your apply template comes into execution like :
<xsl:apply-templates select="/Objects/Object" >
<xsl:sort select="@name" order="ascending" />
</xsl:apply-templates>
it selecting "Objects/Object" name attribute in your XML file and put them in the specified order.
Correct ME, If I am Wrong!!!
Visit My Blog