Re: Re: Move (ascend) an element
Thanks Wendell, Writing it that way makes a lot more sense--my xsl sheets are littered with the literal descendants/parent/child notations. The way you mentioned makes it easier to see what's going on. I'm trying to retain the original attributes from the figure match and the following code seems to work, although I haven't seen many instances with two copy-of's in a row--do you know if this is okay practice?: <xsl:template match="figure[./title/indexterm]"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:copy-of select=".//indexterm"/> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> It seems preferable than recreating each attribute (some are custom) with the <attribute> tag. Anyways thanks for all your help! Naomi Hi Naomi, At 04:27 PM 11/9/2004, you wrote: >I used a modification of the provided example to try >and move indexterms from inside /figure/title to just >above the title, but I seem to be losing my figure >attributes like id and role (because of a shallow >copy?)--doing it this way also for some reason takes >another indexterm from earlier in the xml file and >puts it right before the one I want moved (this, I >have no clue about): > ><xsl:template >match="figure[child::title[child::indexterm]]"> > <xsl:copy> > <xsl:copy-of select="//indexterm"/> "//indexterm" translates to "/descendant-or-self::node()/child::indexterm", meaning all indexterms in the document, which is why you get them. You want ".//indexterm", which collects all the indexterms inside the context node. Not a big deal, but the conventional way to write your match expressions would probably be match="figure[./title/indexterm]" (short for child::figure[self::node()/child::title/child::indexterm]) and match="figure/title/indexterm" (instead of match="indexterm[parent::title[parent::figure]]") They work the same as yours but are a bit easier to read for the XPath-fluent. Cheers, Wendell ====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ====================================================================== __________________________________ Do you Yahoo!? Check out the new Yahoo! Front Page. www.yahoo.com
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