Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 9th, 2006, 02:27 PM
Registered User
 
Join Date: Aug 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can I promote an element by not copying a parent?

I'm in a situation of using an identity template to take everything in my XML file by default, except for a couple of things that I choose not to copy. That part works for simple leaf elements.

But what if the element has children, and I want to keep the children? In other words:

<A>
 <B>
   <C>Foo</C>
 </B>
 <B>
   <C>Bar</C>
 </B>
</A>

What's the trick for leaving out B, and just producing:

<A>
 <C>Foo</C>
 <C>Bar</C>
</A>

I tried matching a template on //B/* and then just using a copy-of ".", but that didn't work.



 
Old August 9th, 2006, 03:52 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Add the template rule

<xsl:template match="B">
  <xsl:apply-templates/>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem adding element to the previous element dani1 XSLT 5 September 10th, 2008 01:38 AM
Value of parent element of current-grouping-key() bonekrusher XSLT 2 September 9th, 2007 06:29 AM
How to delete an element and parent node. crossedge XSLT 1 March 14th, 2006 05:10 AM
Accessing a element of parent window in child wind livehed BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 1 June 28th, 2005 10:26 AM
Is parent first element in series cedar XSLT 2 June 8th, 2005 10:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.