This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Re: XSL-List Digest V3 #915


Hi Alexey,

> I need to restructure the document, i.e. the file
>
> <div name="1">
>      <div name="1.1">
>      </div>
>      <div name="1.2">
>           <div name="1.3">
>           </div>
>      </div>
> </div>
>
> to the normal form
>
> <div name="1">
>      <div name="1.1">
>      </div>
>      <div name="1.2">
>      </div>
>           <div name="1.3">
>           </div>
> </div>

I guess that you're using the name of the div to give the depth that
it should be at? You can find out the level of a div by looking at the
length of the name once you extract all the numbers (i.e. how many .s
there are in it):

  string-length(translate(@name, '1234567890', ''))

Within a template that matches a div, I think you want to apply
templates to those descendant div elements whose name contains one
more . than this div element:

<xsl:variable name="digits" select="'1234567890'" />

<xsl:template match="div">
  <xsl:variable name="level"
    select="string-length(translate(@name, $digits, ''))" />
  <div name="{@name}">
    <xsl:apply-templates
      select="div[string-length(translate(@name, $digits, '')) =
                  $level + 1]" />
  </div>
</xsl:template>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]