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

Re: Re: simple tree problem ...

Subject: Re: Re: simple tree problem ...
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Thu, 25 Oct 2001 08:13:05 -0700 (PDT)
following sibling position 1
Using better data it can be seen that the solution I proposed was wrong!

A small modification to Mike's solution makes it perform correctly (originally it
didn't output the labels of the upper-most nodes):

source xml:
----------
<snip>
    <position id="1">
        <position id="2">
            <position id="3" />
        </position>
        <position id="4">
          <position id="6"/>
        </position>
    </position>
    <position id="5">
         <position id="7"/>
    </position>
</snip>


stylesheet:
----------
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text" />

    <xsl:template match="snip">
      <xsl:apply-templates select="position" mode="visit"/>
      <xsl:apply-templates select="position"/>
    </xsl:template>

    <xsl:template match="position">
        <xsl:apply-templates select="position" mode="visit"/>
        <xsl:apply-templates select="position"/>
    </xsl:template>

    <xsl:template match="position" mode="visit">
        <xsl:value-of select="@id" />
    </xsl:template>
</xsl:stylesheet>


Result:
------
1524367


Cheers,
Dimitre Novatchev.


--- Dimitre Novatchev <dnovatchev@xxxxxxxxx> wrote:
> Maybe this is just a little bit more simple and efficient. Do note, that I cleaned
> the source xml:
> 
> source xml:
> ----------
> <snip>
>     <position id="1">
>         <position id="2">
>             <position id="3" />
>         </position>
>         <position id="4" />
>     </position>
>     <position id="5" />
> </snip>
> 
> 
> stylesheet:
> ----------
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>     <xsl:output method="text"/>
>     <xsl:template match="snip">
>         <xsl:apply-templates select="child::position[1]"/>
>     </xsl:template>
> 
>     <xsl:template match="position">
>         <xsl:value-of select="@id" />
> 
>         <xsl:apply-templates select="following-sibling::position[1]" />
>         <xsl:apply-templates select="child::position[1]" />
>     </xsl:template>
> </xsl:stylesheet>
> 
> 
> Result:
> ------
> 15243
> 
> 
> Cheers,
> Dimitre Novatchev.
> 
> 
> 
> Jörg Heinicke wrote:
> 
> <xsl:template match="snip">
>     <xsl:apply-templates select="descendant::position">
>         <xsl:sort select="count(ancestor::position)"/>
>     </xsl:apply-templates>
> </xsl:template>
> 
> <xsl:template match="position">
>     <!-- do what you want -->
> </xsl:template>
> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Make a great connection at Yahoo! Personals.
> http://personals.yahoo.com
> 


__________________________________________________
Do You Yahoo!?
Make a great connection at Yahoo! Personals.
http://personals.yahoo.com

 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.