[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Re: RE: sequence numbering.

Subject: Re: Re: RE: sequence numbering.
From: Chuck Paussa <cpaussa@xxxxxxxxx>
Date: Tue, 2 Apr 2002 10:16:22 -0800 (PST)
xalan exclude result prefixes
William,

You didn't put in the $ for the variable $this_color. Otherwise it works.

Chuck Paussa

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:xalan = "http://xml.apache.org/xalan" 
                exclude-result-prefixes="xalan">
<xsl:output omit-xml-declaration="yes" method="text"/>
<xsl:key  name = "color" match = "//colorlist/color" use = "@id"/>
<xsl:template match="/">
<xsl:variable name="sorted-color">
<xsl:for-each select="//product">
<xsl:sort select="./color" data-type="text" order="descending"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="xalan:nodeset($sorted-color)/product">
<xsl:variable name="this_color" select="./color"/>
<xsl:number count="product[color=$this_color]"/><xsl:value-of select="$this_color"/>
<xsl:value-of select="key('color',this_color)"/>
<xsl:text>&#xa;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

--- william locksman <vsd18@xxxxxxxxxxxxxx> wrote:
> Hi ,
> Thanks very much to Jeni for sorting my probs out..
> That was really very helpful.
> How ever there is one more problem that popped out.
> Here it goes..
> The xml file..
> <products>
>     <product id = "1">
>     <name>product1</name>
>      <weight>56</weight>
>      <color>11</color>
>     </product>
>     <product id = "2">
>      <name>product2</name>
>      <weight>56</weight>
>      <color>11</color>
>     </product>
>     <product id = "3">
>     <name>product3</name>
>      <weight>56</weight>
>      <color>11</color>
>     </product>
>     <product id = "4">
>     <name>product4</name>
>      <weight>56</weight>
>      <color>12</color>
>     </product>
>     <product id = "5">
>      <name>product5</name>
>      <weight>56</weight>
>      <color>12</color>
>     </product>
>     <colorlist>
>     <color id = "11">
>      <name>red</name>
>     </color>
>     <color id = "12">
>     <name>blue</name>
>     </color>
>     </colorlist>
>   </products>
> Here i was adviced by Jenni to  sort the colors and store it in 
> Variable.. and then use the <xalan:nodeset > for processing.
> in doing so when i try to use the <xsl:key>, it does not seem to 
> give me the desired result.
> i am pasting below the xsl..
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan = 
> "http://xml.apache.org/xalan" exclude-result-prefixes="xalan">
> <xsl:output omit-xml-declaration="yes" method="text"/>
> <xsl:key  name = "color" match = "//colorlist/color" use = 
> "@id"/>
> <xsl:template match="/">
> <xsl:variable name="sorted-color">
> <xsl:for-each select="//product">
> <xsl:sort select="./color" data-type="text" order="descending"/>
> <xsl:copy-of select="."/>
> </xsl:for-each>
> </xsl:variable>
> <xsl:for-each select="xalan:nodeset($sorted-color)/product">
> <xsl:variable name="this_color" select="./color"/>
> <xsl:number count="product[color=$this_color]"/><xsl:value-of 
> select="this_color"/>
> <xsl:value-of select="key('color',this_color)"/>
> <xsl:text>
</xsl:text>
> </xsl:for-each>
> </xsl:template>
> </xsl:stylesheet>
> 
> I was expecting a result that would look like
> 1 blue
> 2 blue
> 1 red
> 2 red
> 3 red
> but the key function is not returning any text..
> and the result is
> 1
> 2
> 1
> 2
> 3
> Am i wrong in my XSL or is there any thing i am missing out and 
> which i am unaware of??
> thanks
> william
> >Hi William,
> >
> > > about the name space,
> > > The Declartion i am using is
> > >
> > > <xsl:stylesheet 
> >xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > > xmlns:xalan="http://xml.apache.org/xslt"
> > > xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
> > > extension-element-prefixes="redirect"
> > >              version="1.0">
> > >
> > > and i am using XALAN processor
> >
> >OK, then you should be able to use xalan:nodeset() extension 
> >function
> >(see http://xml.apache.org/xalan-j/extensionslib.html#nodeset).
> >
> >[It seems likely that the next version of Xalan will support 
> >EXSLT
> >functions. See the recent mail from Don Leslie
> >(http://aspn.activestate.com/ASPN/Mail/Message/exslt/1083089). 
> >With
> >that version, you'll be able to use the namespace
> >http://exslt.org/common, and the function exsl:node-set(), which 
> >would
> >make your stylesheet portable across a range of processors, 
> >including
> >Saxon, libxslt, 4XSLT and jd.xslt.]
> >
> >Cheers,
> >
> >Jeni
> >
> >---
> >Jeni Tennison
> >http://www.jenitennison.com/
> >
> >
> >  XSL-List info and archive:  
> >http://www.mulberrytech.com/xsl/xsl-list
> >
> 
> 
> On Wed, 27 Mar 2002 william locksman wrote :
> >Hi the solution Michael Suggested seems to fit my purpose, But 
> >Since i am a newbie to XSL , I do not know how to form a 
> >temporary tree that contains sorted sequence.
> >Michael's explaination made me pretty much clear of what has to 
> >be done. But i do not know how it has to be done.
> >If any one can please suggest me how to go about doing it or give 
> >me a link to any reference document, It should be of much help to 
> >me
> >Thanks
> >William
> >
> >On Tue, 26 Mar 2002 Michael Kay wrote :
> >><xsl:number> gives you the position of the element in the source 
> >>tree, not
> >>in the sorted sequence. To get the number in the sorted 
> >>sequence, do a
> >>two-phase transformation: create a temporary tree that contains 
> >>the sorted
> >>products, then process this (using xx:node-set()) to add the 
> >>numbers. To get
> >>the number for a product among all the products of the same 
> >>colour, use
> >><xsl:number count="product[color=$this_color]"/>
> >>
> >>Michael Kay
> >>Software AG
> >>home: Michael.H.Kay@xxxxxxxxxxxx
> >>work: Michael.Kay@xxxxxxxxxxxxxx
> >>
> >> > -----Original Message-----
> >> > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> >> > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of 
> >>william
> >> > locksman
> >> > Sent: 26 March 2002 16:34
> >> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> >> > Subject:  sequence numbering
> >> >
> >> >
> >> > <products>
> >> >   <product id = "1">
> >> >   <name>product1</name>
> >> >    <weight>56</weight>
> >> >    <color>blue</color>
> >> >   </product>
> >> >   <product id = "2">
> >> >    <name>product2</name>
> >> >    <weight>56</weight>
> >> >    <color>red</color>
> >> >   </product>
> >> >   <product id = "3">
> >> >   <name>product3</name>
> >> >    <weight>56</weight>
> >> >    <color>red</color>
> >> >   </product>
> >> >   <product id = "4">
> >> >   <name>product4</name>
> >> >    <weight>56</weight>
> >> >    <color>blue</color>
> >> >   </product>
> >> >   <product id = "5">
> >> >    <name>product5</name>
> >> >    <weight>56</weight>
> >> >    <color>blue</color>
> >> >   </product>
> >> > </products>
> >> >
> >> > for the above xml for all the color elements in the xml 
> >>file,
> 
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://http://taxes.yahoo.com/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.