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

Re: Dealing without global counters

Subject: Re: Dealing without global counters
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Wed, 12 Nov 2003 07:21:27 +0100
javascript dbrecord
This transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:order="my:order"
 exclude-result-prefixes="order"
 >
  <xsl:output method="text"/>
  <order:order>
    <n n="para" p="1"/>
    <n n="image" p="2"/>
    <n n="table" p="3"/>
  </order:order>

  <xsl:variable name="vOrder" select="document('')/*/order:*"/>

  <xsl:template match="chapter">
        db[1]=new dbRecord(chapter stuff)<xsl:text/>
      <xsl:for-each select="/chapter/*[self::para or self::image or
self::table]">
        <xsl:sort select="$vOrder/*[@n = name(current())]/@p"/>

        <xsl:variable name="vPos" select="position() + 1"/>
        db[<xsl:value-of select="$vPos"/>]<xsl:text/>
        <xsl:value-of select="concat('=new dbRecord(', name(), ' stuff)')"/>
      </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

when applied on your source.xml:

<chapter>
      <para>
      </para>
      <para>
      </para>
      <image>
      </image>
      <para>
      </para>
      <image>
      </image>
      <table>
      </table>
      <para>
      </para>
</chapter>

produces the wanted result:

        db[1]=new dbRecord(chapter stuff)
        db[2]=new dbRecord(para stuff)
        db[3]=new dbRecord(para stuff)
        db[4]=new dbRecord(para stuff)
        db[5]=new dbRecord(para stuff)
        db[6]=new dbRecord(image stuff)
        db[7]=new dbRecord(image stuff)
        db[8]=new dbRecord(table stuff)


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Robert Ogden" <Robert.Ogden@xxxxxxxx> wrote in message
news:sfb12976.033@xxxxxxxxxxxxxxxxxxxxxxxxxx
> I have done a bit of reading, and it seems global counters are not the
> answer in XSLT. That being said I have a problem (normally solved by a
> global counter) I need to solve. I'm building a TOC for an XML
> document.
> The best way is to offer xml structure and intended output.
>
> XML:
> <chapter>
>     <para>
>     </para>
>     <para>
>     </para>
>     <image>
>     </image>
>     <para>
>     </para>
>     <image>
>     </image>
>     <table>
>     <table>
>     <para>
>     <para>
> </chapter>
>
> Output (this output is a javascript array for an expandable TOC)
> db[1]=new dbRecord(chapter stuff)
> db[2]=new dbRecord(first para stuff)
> db[3]=new dbRecord(second para stuff)
> db[4]=new dbRecord(third para stuff)
> db[5]=new dbRecord(fourth para stuff)
> db[6]=new dbRecord(first image stuff)
> db[7]=new dbRecord(second image stuff)
> db[8]=new dbRecord(first table stuff)
>
> What I want to do is output a chapter, all text in a chapter, then all
> images for a chapter, and lastly all tables for a chapter.
> This is done repetitively for each chapter.
>
> For the text, calling a template that contains <xsl:number> would work.
> I would get a sequential numbering in the db[] (which IS required,
> db[number] where number is sequential 1 to N). But as you see the
> figures and tables are interlaced in the XML, and not desired to be that
> way in the TOC.
>
> Any help would be appreciated.
> Thanks,
>
> Robert Ogden
> IETM Developer
> Navy Programs
> (763) 572-7121
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>




 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-2013 All Rights Reserved.