p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   need to output the content of an element with out the content of it's children (http://p2p.wrox.com/showthread.php?t=87434)

tonypg May 3rd, 2012 07:21 AM

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.

Martin Honnen May 3rd, 2012 07:25 AM

Code:

<xsl:template match="Parent">
  <xsl:copy>
    <xsl:apply-templates select="text()"/>
  </xsl:copy>
</xsl:template>


mhkay May 3rd, 2012 07:30 AM

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"/>


All times are GMT -4. The time now is 09:44 PM.

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