[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: extrapolating attributes to child nodes
>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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|