xsl-list
[Top] [All Lists]

RE: read/write in the same xml file

2003-06-13 06:03:19
Hi

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
abbouh
Sent: Tuesday, June 10, 2003 4:25 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] read/write in the same xml file


is there some propositions?

(...)

If you only need to write a TOC you could try this stylesheet. You'll need a
node-set function, so you'll need to change the microsoft namespace to the
one used by your processor

Hope that this helps you.

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:ms="urn:schemas-microsoft-com:xslt">
 <xsl:variable name="head" select="'paragraph'"></xsl:variable>
 
 <xsl:template match="document">
  <xsl:text>table of contents:&#10;</xsl:text>
  <xsl:apply-templates select="para">
   <xsl:with-param name="sizes">
    <xsl:apply-templates select="para" mode="psize"></xsl:apply-templates>
   </xsl:with-param>
  </xsl:apply-templates>
  <xsl:text>&#10;&#10;</xsl:text>
  <xsl:apply-templates select="para" mode="display"></xsl:apply-templates>
 </xsl:template>
 
 <xsl:template match="para">
  <xsl:param name="sizes"></xsl:param>
  <xsl:variable name="pos" select="position()"></xsl:variable>
  <xsl:variable name="cur"
select="ms:node-set($sizes)/count[position()=$pos]"></xsl:variable>
  <xsl:value-of select="concat($head,$pos,'&#9;')"/>
  <xsl:value-of select="sum($cur/preceding-sibling::count/word) +
(string-length(concat($head,$pos)) + 2) *
(count($cur/preceding-sibling::count ) + 1)"/>
  <xsl:text>&#9;</xsl:text>
  <xsl:value-of select="sum($cur/preceding-sibling::count/word) +
sum($cur/word) + (string-length(concat($head,$pos)) + 2) *
(count($cur/preceding-sibling::count ) + 1)"/>
  <xsl:text>&#10;</xsl:text>
 </xsl:template>
 
 <xsl:template match="para" mode="psize">
  <count>
   <xsl:apply-templates mode="psize"></xsl:apply-templates>
  </count>
 </xsl:template>
 
 <xsl:template match="word" mode="psize">
  <word><xsl:value-of select="string-length(.) + 1"/></word>
 </xsl:template>
 
 <xsl:template match="para" mode="display">
  <xsl:value-of select="concat($head,position(),'&#10;')"/>
  <xsl:apply-templates select="word" mode="display"></xsl:apply-templates>
 </xsl:template>
 
 <xsl:template match="word" mode="display">
  <xsl:apply-templates></xsl:apply-templates>
  <xsl:text>&#10;</xsl:text>
 </xsl:template>
</xsl:stylesheet>


 



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