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

RE: read/write in the same xml file

Subject: RE: read/write in the same xml file
From: Jarno.Elovirta@xxxxxxxxx
Date: Wed, 11 Jun 2003 14:30:16 +0300
select read write
Hi,

> this is an example for what i want to do:
> 
> i supose this is my xml file:
> <document>
> <para>
> <word>aaa</word>
> <word>bbb</word>
> <word>ccc</word>
> <word>ddd</word>
> <word>eee</word>
> </para>
> <para>
> <word>kkk</word>
> <word>fff</word>
> <word>mmm</word>
> <word>ppp</word>
> </para>
> </document>
> 
> my output file should have this structure:
> 
> table of contents:
> paragraph1  12    32
> paragraph2  44  59
> 
> paragraph1
> aaa
> bbb
> ccc
> ddd
> eee
> paragraph2
> kkk
> fff
> mmm
> ppp
> 
> 
> so  the first paragraph begin in character 12 and finish in 
> character 32
> in the output file.

  <xsl:output method="text"/>
  <xsl:strip-space elements="*"/>
  <xsl:template match="document">
    <xsl:text>table of contents:&#xA;</xsl:text>
    <xsl:call-template name="counter" />
    <xsl:text>&#xA;</xsl:text>
    <xsl:for-each select="para">
      <xsl:text>paragraph</xsl:text>
      <xsl:value-of select="position()"/>
      <xsl:text>&#xA;</xsl:text>
      <xsl:for-each select="word">
        <xsl:value-of select="."/>
        <xsl:text>&#xA;</xsl:text>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:template>
  <xsl:template name="counter">
    <xsl:param name="offset" select="0"/>
    <xsl:param name="node" select="para[1]" />
    <xsl:param name="count" select="1"/>
    <xsl:text>paragraph</xsl:text>
    <xsl:value-of select="$count"/>
    <xsl:text>  </xsl:text>
    <xsl:variable name="start" select="$offset + 11 + string-length(string($count))"/>
    <xsl:value-of select="$start"/>
    <xsl:text>  </xsl:text>
    <xsl:if test="$count = 1">
      <xsl:text>  </xsl:text>
    </xsl:if>
    <xsl:variable name="end" select="$start + count($node/word) + boolean($node/following-sibling::para) - 1 + string-length($node)"/>
    <xsl:value-of select="$end"/>
    <xsl:text>&#xA;</xsl:text>
    <xsl:if test="$node/following-sibling::para">
      <xsl:call-template name="counter">
        <xsl:with-param name="offset" select="$end"/>
        <xsl:with-param name="node" select="$node/following-sibling::para[1]"/>
        <xsl:with-param name="count" select="$count + 1"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

Feels really silly to write stylesheets like this...

Cheers,

Jarno - Conjure One: Tears From The Moon

 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.