It works!  Thanks a lot Henry.

 

Like you mention, I would like to have the same input XML as my output XML (with the netPrice sorted) but the attributes are not copied even if I have the xsl:copy.  Can you help me on this? 

 

I tried to add my namespace but it’s not working anymore with it.  I read many web pages and tried many things.  Here is my new stylesheet with my namespace, what’s wrong:

 

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

 xmlns:aco="http://www.org/TRIP2004A/01"

version="1.0">

  <xsl:output method="xml"/>

 

  <xsl:template match="aco:/GetProductOptionsResponse/DetailedProduct/ProductOptionGroup/ProductOption">

    <xsl:copy>

       <xsl:apply-templates>

         <xsl:sort data-type="number" select="@netAmount" order="ascending"/>

       </xsl:apply-templates>

    </xsl:copy>

  </xsl:template>

 

  <xsl:template match="*">

    <xsl:copy>

      <xsl:apply-templates/>

    </xsl:copy>

  </xsl:template>

</xsl:stylesheet>

 

 

Thanks a lot again!

Stephane

 

 

-----Message d'origine-----
De : Henry Zongaro [mailto:[EMAIL PROTECTED]
Envoyé : October 20, 2005 13:37
À : [EMAIL PROTECTED]
Cc : [email protected]
Objet : Re: xalan xsl:sort does not sort!

 

Hi, Stephane.

 

"Stephane Dion" <[EMAIL PROTECTED]> wrote on 2005-10-20 09:51:08 AM:

> I?m trying to sort each block of NetPrice element by the attribute

> NetAmount.  In each ProductOption, I have multiple NetPrice element

>

> Check my example below.

 

Focusing on the first template in your sample:

 

>   <xsl:template

>

match="/GetProductOptionsResponse/DetailedProduct/ProductOptionGroup/ProductOption">

>     <xsl:copy>

>        <xsl:apply-templates>

>          <xsl:sort data-type="number"

>                    select="NetPrice/@netAmount"

>                    order="ascending"/>

>        </xsl:apply-templates>

>     </xsl:copy>

>   </xsl:template>

 

Each node selected for the xsl:apply-templates instruction, is used as the

context node to evaluate the select _expression_ in the xsl:sort.  With your

input document, the xsl:apply-templates selects the NetPrice children of

ProductOption.  Each NetPrice node becomes the context node for evaluating

the _expression_ NetPrice/@netAmount in the xsl:sort, which results in an

empty node set, because no NetPrice element has a NetPrice element as a

child.

 

If you change the xsl:sort to the following, it should work:

 

 

         <xsl:sort data-type="number"

                   select="@netAmount"

                   order="ascending"/>

 

I hope that helps.

 

As an aside, I noticed that the elements in your input document have a

non-null namespace, but you didn't use that in the match pattern for the

first template.  I also noticed that you're not copying any attributes.

I'm guessing that both of those problems arose when you produced your

example stylesheet, and the original stylesheet handles those things

correctly, but I thought I'd point them out anyway just in case.

 

Thanks,

 

Henry

------------------------------------------------------------------

Henry Zongaro      Xalan development

IBM SWS Toronto Lab   T/L 969-6044;  Phone +1 905 413-6044

mailto:[EMAIL PROTECTED]

 

 

Reply via email to