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

Re: Keeping track of parents

Subject: Re: Keeping track of parents
From: "Anthony E." <apwebdesign@xxxxxxxxx>
Date: Fri, 13 Jul 2001 16:07:10 -0700 (PDT)
Re:  Keeping track of parents
> Most of it I can generate, but how can I fill the
> parentid? If there is no
> ancestor-element named <somenode> then the parent_id
> should be 0, else the
> parent_id should be the group_id of the ancestor.

someone can probably better answer this than me, but i
had a similar situation and came up with this:


<xsl:template match="somenode">
  <xsl:choose>
    <xsl:when test="ancestor::somenode">
    <xsl:variable name="parent_id"
select="parent::somenode[ancestor::somenode]/@id"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:variable name="parent_id" select="'0'"/>
    </xsl:otherwise>
  </xsl:choose>

  <!-- print to test $parent_id -->
  parent_id = <xsl:value-of select="$parent_id"/>

</xsl:template>



--- Christian Cäsar <caesar@xxxxxxxxxxxx> wrote:
> Hi there,
> 
> I'm a newbie, so please be patient with me if I
> cannot explain my problem
> as I should. I am quite stumped on this.
> 
> This is my problem:
> 
> I have an XML-File with a structure like this
> (simplified):
> 
> <somenode id="1">
>   <more_elements/>
>   <somenode id="2">
>     <more_elements/>
>     <somenode id="3">
>       <more_elements/>
>     </somenode>
>   <somenode id="4">
>     <more_elements/>
>   </somenode>
> </somenode>
> 
> That is, the element <somenode> can have children
> that are also called
> <somenode>.
> 
> My result xml should look like this:
> 
> <structure>
>   <group_name
> value="some_value_from_more_elements"/>
>   <group_id value="some_unique_id_for_somenode"/>
>   <parent_id value="group_id_of_somenodes_parent"/>
> </structure>
> <structure>
>   <group_name
> value="some_value_from_more_elements"/>
>   <group_id value="some_unique_id"/>
>   <parent_id value="group_id_of_somenodes_parent"/>
> </structure>
> <structure>
>   <group_name
> value="some_value_from_more_elements"/>
>   <group_id value="some_unique_id"/>
>   <parent_id value="group_id_of_somenodes_parent"/>
> </structure>
> <structure>
>   <group_name
> value="some_value_from_more_elements"/>
>   <group_id value="some_unique_id"/>
>   <parent_id value="group_id_of_somenodes_parent"/>
> </structure>
> 
> Most of it I can generate, but how can I fill the
> parentid? If there is no
> ancestor-element named <somenode> then the parent_id
> should be 0, else the
> parent_id should be the group_id of the ancestor.
> 
> If it matters: I'm using xalan.
> 
> Thanks for helping me,
> Christian
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.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.