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

RE: extrapolating attributes to child nodes

Subject: RE: extrapolating attributes to child nodes
From: "DuCharme, Robert" <Robert.DuCharme@xxxxxxxxxx>
Date: Fri, 25 Aug 2000 18:07:18 -0400
ducharme email directory contact
>I want to convert xml as follows:
>From:
><set = 5>
>  <A>
(some deleted)
>  </A>
>  </set=5>
>  To:
>  <directory name="A" global_id="4:5" gid="10" perm="777" />
>  <directory name="B" global_id="5:5" gid="11" perm="444" />
>
>  Where global_id=uid:set, and set. Anything other than set and elements 
>under
>  <attrib> can be safely assumed to be directories. A set is to be listed
as
>  part of global_id in each child node.
>
>  I use the following hardcoded xslt such as <xsl:template match="A">..., 
>but
>  I am seeking more dynamic solution such that it would parse from the root

>node,
>  and construct global_id from the <set> and <uid>.
>

Here's something. By "more dynamic," it doesn't count on the directory
element's names being "A" and "B" but instead searches from the root for any
descendant element with an attrib element as a child. Also, <set = 5></set =
5> doesn't make any sense, so I changed it to <set uid="5"></set>before I
ran this to test it. 

  <xsl:template match="/">
    <xsl:for-each select="//*[attrib]">
      <directory name="{name()}" 
       global_id="{normalize-space(attrib/uid)}:{ancestor::node()/@uid}"
       gid="{normalize-space(attrib/gid)}" 
       perm="{normalize-space(attrib/perm)}"/><xsl:text><!-- carriage return
-->
</xsl:text>
    </xsl:for-each>
  </xsl:template>

Is this what you meant?

Bob DuCharme          www.snee.com/bob           <bob@  
snee.com>  "The elements be kind to thee, and make thy
spirits all of comfort!" Anthony and Cleopatra, III ii


 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.