OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] <xsl:number> question

[ Lists Home | Date Index | Thread Index ]

At 2006-05-23 19:07 -0400, Culler, Jeff S. wrote:
>  Would anyone care to point in me in the right direction in solving a
>numbering problem?

XSLT and XPath questions would be better posted to the following list:

   http://www.mulberrytech.com/xsl/xsl-list

There are a number of subscribers who would enthusiastically respond 
to such questions.

There is also an *excellent* XSLT FAQ at:

   http://www.dpawson.co.uk

>   Here is the xml
>         <Product>
>                 <page>
>                         <PageId>Business</PageId>
>                 </page>
>                 <page>
>                         <PageId>Business</PageId>
>                 </page>
>                 <page>
>                         <PageId>Sports</PageId>
>                 </page>
>                 <page>
>                         <PageId>Sports</PageId>
>                 </page>
>                 <page>
>                         <PageId>Business</PageId>
>                 </page>
>                 <page>
>                         <PageId>Business</PageId>
>                 </page>
>         </Product>
>
>  I am trying to get text output like this
>
>                         Business-01
>                         Business-02
>                         Sports-01
>                         Sports-02
>                         Business-04
>                         Business-05

I'm assuming you want "-03", "-04" for the last two ... or did you 
want "-05","-06"?  Otherwise I'm not sure how that numbering works.

>   Using the "<xsl:text>-</xsl:text><xsl:number   format="01" />" after each
>"<PageId>" tag numbers gets the correct format,
>   however, "Sports" is numbered 03 and 04, with the last two "Business"
>numbered with 05 and 06.

There is a nuance here in that what is being counted depends on 
values at the current node() ... match patterns cannot use the 
current() function, nor can they use variables, so the intuition to 
use either in the count= attribute won't work.

>   I am working on a way to breaking the number count when a new text value
>is encountered in the "PageId" tag.
>   and resuming the number if the text is again resumed.
>
>   Can the attributes associated with <xsl:number> do the trick, or will I
>need to start looking at using other xsl tag logic ?

The answer below uses attributes with <xsl:number/>, but only to get 
the formatting.  I believe one has to use axes and not a match 
pattern because the match pattern needed is dynamic and XSLT 1 says 
they have to be static.

I hope this helps.

. . . . . . . . . Ken

T:\ftemp>type culler.xml
<?xml version="1.0" encoding="US-ASCII"?>
<Product>
         <page>
                 <PageId>Business</PageId>
         </page>
         <page>
                 <PageId>Business</PageId>
         </page>
         <page>
                 <PageId>Sports</PageId>
         </page>
         <page>
                 <PageId>Sports</PageId>
         </page>
         <page>
                 <PageId>Business</PageId>
         </page>
         <page>
                 <PageId>Business</PageId>
         </page>
</Product>
T:\ftemp>type culler.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                 version="1.0">

<xsl:output method="text"/>

<xsl:template match="page">
   <xsl:value-of select="PageId"/>
   <xsl:number format="-01"
     value="count( preceding-sibling::page[PageId=current()/PageId] )+1"/>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>xslt culler.xml culler.xsl con

         Business-01
         Business-02
         Sports-01
         Sports-02
         Business-03
         Business-04

T:\ftemp>

--
Registration open for XSLT/XSL-FO training: Wash.,DC 2006-06-12/16
Also for XSL-FO/XSLT training:    Minneapolis, MN 2006-07-31/08-04
Also for XML/XSLT/XSL-FO/UBL training: Varo,Denmark 06-09-25/10-06
World-wide corporate, govt. & user group UBL, XSL, & XML training.
G. Ken Holman                 mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/x/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug'05  http://www.CraneSoftwrights.com/x/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS