xsl-list
[Top] [All Lists]

xsl:sort working for xsl:for-each but not for xsl:apply-templates

2005-03-01 13:16:59
Hi everyone. Please take a look to the xml and xsl and let me know what I am
missing ... When I use as in the example below xsl:apply-templates I always
get as result "Start","MotoGP 1" no matter how the sorting order is defined.
If I use xsl:for-each the sort works .... 

Thanks in advance
Nestor

XML
-----
<ApplicationCatalogue name="35000_truetones">
        <Category name="dorna" description="">
                <Product code="TT070000004" position="1">
                        <Alias isDefault="true">
                                <Name>START</Name>
                                <Extra></Extra>
                        </Alias>
                        <Attributes>
        
<OTAobject_general_title>Start</OTAobject_general_title>
        
<OTAobject_otaother_rights>Dorna</OTAobject_otaother_rights>
        
<OTAobject_general_name>TT070000004</OTAobject_general_name>
        
<OTAobject_otaother_namepreview>Start</OTAobject_otaother_namepreview>
        
<OTAobject_general_language>0</OTAobject_general_language>
        
<OTAobject_otaother_direct>1</OTAobject_otaother_direct>
        
<OTAobject_otaother_author>Artist4</OTAobject_otaother_author>
        
<OTAobject_otadescr_type>truetones</OTAobject_otadescr_type>
        
<OTAobject_general_category></OTAobject_general_category>
                        </Attributes>
                </Product>
                <Product code="TT070000002" position="2">
                        <Alias isDefault="true">
                                <Name>MOTO2</Name>
                                <Extra></Extra>
                        </Alias>
                        <Attributes>
                                <OTAobject_general_title>MotoGP
2</OTAobject_general_title>
        
<OTAobject_otaother_rights>Dorna</OTAobject_otaother_rights>
        
<OTAobject_general_name>TT070000002</OTAobject_general_name>
                                <OTAobject_otaother_namepreview>MotoGP
2</OTAobject_otaother_namepreview>
        
<OTAobject_general_language>0</OTAobject_general_language>
        
<OTAobject_otaother_direct>1</OTAobject_otaother_direct>
        
<OTAobject_otadescr_type>truetones</OTAobject_otadescr_type>
        
<OTAobject_general_category></OTAobject_general_category>
                        </Attributes>
                </Product>
                <Product code="TT070000003" position="3">
                        <Alias isDefault="true">
                                <Name>CRASH</Name>
                                <Extra></Extra>
                        </Alias>
                        <Attributes>
        
<OTAobject_general_title>Crash</OTAobject_general_title>
        
<OTAobject_otaother_rights>Dorna</OTAobject_otaother_rights>
        
<OTAobject_general_name>TT070000003</OTAobject_general_name>
        
<OTAobject_otaother_namepreview>Crash</OTAobject_otaother_namepreview>
        
<OTAobject_general_language>0</OTAobject_general_language>
        
<OTAobject_otaother_direct>1</OTAobject_otaother_direct>
        
<OTAobject_otadescr_type>truetones</OTAobject_otadescr_type>
        
<OTAobject_general_category></OTAobject_general_category>
                        </Attributes>
                </Product>
                <Product code="TT070000001" position="4">
                        <Alias isDefault="true">
                                <Name>MOTO1</Name>
                                <Extra></Extra>
                        </Alias>
                        <Attributes>
                                <OTAobject_general_title>MotoGP
1</OTAobject_general_title>
        
<OTAobject_otaother_rights>Dorna</OTAobject_otaother_rights>
        
<OTAobject_general_name>TT070000001</OTAobject_general_name>
                                <OTAobject_otaother_namepreview>MotoGP
1</OTAobject_otaother_namepreview>
        
<OTAobject_general_language>0</OTAobject_general_language>
        
<OTAobject_otaother_direct>1</OTAobject_otaother_direct>
        
<OTAobject_otaother_author>Artist1</OTAobject_otaother_author>
        
<OTAobject_otadescr_type>truetones</OTAobject_otadescr_type>
        
<OTAobject_general_category></OTAobject_general_category>
                        </Attributes>
                </Product>
        </Category>
        <Category name="new" description="">
                <Product code="TT070000004" position="0">
                        <Alias isDefault="true">
                                <Name>START</Name>
                                <Extra></Extra>
                        </Alias>
                        <Attributes>
        
<OTAobject_general_title>Start</OTAobject_general_title>
        
<OTAobject_otaother_rights>Dorna</OTAobject_otaother_rights>
        
<OTAobject_general_name>TT070000004</OTAobject_general_name>
        
<OTAobject_otaother_namepreview>Start</OTAobject_otaother_namepreview>
        
<OTAobject_general_language>0</OTAobject_general_language>
        
<OTAobject_otaother_direct>1</OTAobject_otaother_direct>
        
<OTAobject_otaother_author>Artist4</OTAobject_otaother_author>
        
<OTAobject_otadescr_type>truetones</OTAobject_otadescr_type>
        
<OTAobject_general_category></OTAobject_general_category>
                        </Attributes>
                </Product>
                <Product code="TT070000001" position="0">
                        <Alias isDefault="true">
                                <Name>MOTO1</Name>
                                <Extra></Extra>
                        </Alias>
                        <Attributes>
                                <OTAobject_general_title>MotoGP
1</OTAobject_general_title>
        
<OTAobject_otaother_rights>Dorna</OTAobject_otaother_rights>
        
<OTAobject_general_name>TT070000001</OTAobject_general_name>
                                <OTAobject_otaother_namepreview>MotoGP
1</OTAobject_otaother_namepreview>
        
<OTAobject_general_language>0</OTAobject_general_language>
        
<OTAobject_otaother_direct>1</OTAobject_otaother_direct>
        
<OTAobject_otaother_author>Artist1</OTAobject_otaother_author>
        
<OTAobject_otadescr_type>truetones</OTAobject_otadescr_type>
        
<OTAobject_general_category></OTAobject_general_category>
                        </Attributes>
                </Product>
        </Category>
        <Category name="top" description="">
                <Product code="TT070000004" position="0">
                        <Alias isDefault="true">
                                <Name>START</Name>
                                <Extra></Extra>
                        </Alias>
                        <Attributes>
        
<OTAobject_general_title>Start</OTAobject_general_title>
        
<OTAobject_otaother_rights>Dorna</OTAobject_otaother_rights>
        
<OTAobject_general_name>TT070000004</OTAobject_general_name>
        
<OTAobject_otaother_namepreview>Start</OTAobject_otaother_namepreview>
        
<OTAobject_general_language>0</OTAobject_general_language>
        
<OTAobject_otaother_direct>1</OTAobject_otaother_direct>
        
<OTAobject_otaother_author>Artist4</OTAobject_otaother_author>
        
<OTAobject_otadescr_type>truetones</OTAobject_otadescr_type>
        
<OTAobject_general_category></OTAobject_general_category>
                        </Attributes>
                </Product>
                <Product code="TT070000001" position="0">
                        <Alias isDefault="true">
                                <Name>MOTO1</Name>
                                <Extra></Extra>
                        </Alias>
                        <Attributes>
                                <OTAobject_general_title>MotoGP
1</OTAobject_general_title>
        
<OTAobject_otaother_rights>Dorna</OTAobject_otaother_rights>
        
<OTAobject_general_name>TT070000001</OTAobject_general_name>
                                <OTAobject_otaother_namepreview>MotoGP
1</OTAobject_otaother_namepreview>
        
<OTAobject_general_language>0</OTAobject_general_language>
        
<OTAobject_otaother_direct>1</OTAobject_otaother_direct>
        
<OTAobject_otaother_author>Artist1</OTAobject_otaother_author>
        
<OTAobject_otadescr_type>truetones</OTAobject_otadescr_type>
        
<OTAobject_general_category></OTAobject_general_category>
                        </Attributes>
                </Product>
                <Product code="TT070000003" position="0">
                        <Alias isDefault="true">
                                <Name>CRASH</Name>
                                <Extra></Extra>
                        </Alias>
                        <Attributes>
        
<OTAobject_general_title>Crash</OTAobject_general_title>
        
<OTAobject_otaother_rights>Dorna</OTAobject_otaother_rights>
        
<OTAobject_general_name>TT070000003</OTAobject_general_name>
        
<OTAobject_otaother_namepreview>Crash</OTAobject_otaother_namepreview>
        
<OTAobject_general_language>0</OTAobject_general_language>
        
<OTAobject_otaother_direct>1</OTAobject_otaother_direct>
        
<OTAobject_otadescr_type>truetones</OTAobject_otadescr_type>
        
<OTAobject_general_category></OTAobject_general_category>
                        </Attributes>
                </Product>
        </Category>
</ApplicationCatalogue>

XSLT
----
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
        <xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
<xsl:template match="/">        
        <xsl:apply-templates
select="/ApplicationCatalogue/Category[(_at_)name='new']/Product"> 
        <xsl:sort select="Attributes/OTAobject_general_title"
order="descending"/>   
                
         </xsl:apply-templates> 
</xsl:template>
 
<xsl:template match="Product">
   <xsl:value-of select="Attributes/OTAobject_general_title"/><br/>
</xsl:template>


</xsl:stylesheet>

-----Original Message-----
From: Joris Gillis [mailto:roac(_at_)pandora(_dot_)be] 
Sent: Tuesday, March 01, 2005 3:05 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] is recursion the best way to solve this?

Tempore 20:44:51, die 03/01/2005 AD, hinc in  
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com scripsit anil jacob 
<anujcb(_at_)yahoo(_dot_)com>:

I have been trying to write an xsl transfor for
converting the following src xml to dest xml. No
success yet, wondering if anyone of you have faced
similar problem, appreciate if you could share any
ideas. The problem is how to wrap the OuterTag over
the InnerTag and the OuterTag can be nested.

Hi,

Playing around with 'xsl:apply-templates' and 'xsl:copy' can do the trick  
(there are plenty of other ways too)

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

<xsl:template match="/Object">
        <Root>
                <xsl:apply-templates select="*[1]"/>
        </Root>
</xsl:template>

<xsl:template match="/Object/*">
        <xsl:copy/>
        <xsl:apply-templates select="following-sibling::Object/*[1]"/>
</xsl:template>

<xsl:template match="*">
        <xsl:copy>
                <xsl:apply-templates
select="following-sibling::Object/*[1]"/>
        </xsl:copy>
</xsl:template>

</xsl:stylesheet>


But I do wonder why the wanted output is not like this:
<Root>
        <HeaderTag>
                <OuterTag>
                        <InnerTag/>
                </OuterTag>
                <InnerTag/>
                <OuterTag>
                        <OuterTag>
                                <InnerTag/>
                        </OuterTag>
                        <InnerTag/>
                </OuterTag>
        </HeaderTag>
</Root>




regards,
-- 
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
"Et ipsa scientia potestas est"  - Francis Bacon , Meditationes sacrae

--~------------------------------------------------------------------
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>
--~--



<Prev in Thread] Current Thread [Next in Thread>