Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old May 3rd, 2012, 07:21 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default need to output the content of an element with out the content of it's children

Code:
<Parent>
<Child>FOO</Child>
I am all that should be outputted
<Child>FOO</Child>
</Parent>
This is an example of the section of xlm that i have, what i am trying to achieve is to output the parent element but not its children.
Is there any way to do this with Xpath. Have looked for the last 3hrs on the net for a solution but not joy.
  #2 (permalink)  
Old May 3rd, 2012, 07:25 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Code:
<xsl:template match="Parent">
  <xsl:copy>
     <xsl:apply-templates select="text()"/>
  </xsl:copy>
</xsl:template>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
  #3 (permalink)  
Old May 3rd, 2012, 07:30 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You could tackle this with a stylesheet that consists of two template rules: a default rule that copies everything (the "identity template"):

Code:
<xsl:template match="*">
  <xsl:copy>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>
plus a rule that defines the exceptions:

Code:
<xsl:template match="Parent/Child"/>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference


Similar Threads
Thread Thread Starter Forum Replies Last Post
Identify element based on the element data/content ROCXY XSLT 7 September 8th, 2011 02:48 AM
Field content prefixes in output xml? CAMc XSLT 2 February 16th, 2011 12:07 PM
How to output the entire content to a string sunnyman XML 6 November 29th, 2007 10:48 PM





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