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 March 16th, 2011, 01:42 PM
Registered User
 
Join Date: Apr 2009
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default XSLT Exclude Parent and children from XML

Folks -

I've looked at more examples of this question than I care to think about. Martin Honnen figures prominently in answering many of them. I have tried every permutation of 'match= ' and 'apply-templates' that I can conceive of and YET to get the desired result!

Put simply, I'd like to output an XML document without the Characteristic nodes and their child nodes. Clearly I'm doing something wrong - can someone explain in plain English what it is I've done wrong with this XSL?


The document I'm working with:

<?xml version="1.0" encoding="UTF-8"?>
<ProductMovementReport xmlns="urn:cidx:names:specification:ces:schema:all :5:0" Version="5.0">
<ProductMovementProductLineItem>
<LineNumber>7000</LineNumber>
<ProductIdentification>
<ProductIdentifier Agency="UPC">070183678440</ProductIdentifier>
</ProductIdentification>
<ProductQuantity>
<Measurement>
<MeasurementValue>3.00</MeasurementValue>
<UnitOfMeasureCode Domain="UN-Rec-20">EA</UnitOfMeasureCode>
</Measurement>
</ProductQuantity>
<Characteristic>
<CharacteristicCode Domain="Other">Longitude</CharacteristicCode>
<CharacteristicDescription>-77.50773000</CharacteristicDescription>
</Characteristic>
<Characteristic>
<CharacteristicCode Domain="Other">Latitude</CharacteristicCode>
<CharacteristicDescription>37.60180500</CharacteristicDescription>
</Characteristic>
<Characteristic>
<CharacteristicCode Domain="Other">netAcres</CharacteristicCode>
<CharacteristicDescription>250.0000</CharacteristicDescription>
</Characteristic>
</ProductMovementProductLineItem>
</ProductMovementReport>

Desired output:
<?xml version="1.0" encoding="UTF-8"?>
<ProductMovementReport xmlns="urn:cidx:names:specification:ces:schema:all:5:0" Version="5.0">
<ProductMovementProductLineItem>
<LineNumber>7000</LineNumber>
<ProductIdentification>
<ProductIdentifier Agency="UPC">070183678440</ProductIdentifier>
</ProductIdentification>
<ProductQuantity>
<Measurement>
<MeasurementValue>3.00</MeasurementValue>
<UnitOfMeasureCode Domain="UN-Rec-20">EA</UnitOfMeasureCode>
</Measurement>
</ProductQuantity>
</ProductMovementProductLineItem>
</
ProductMovementReport>


Most recent futile attempt at removing <Characteristic> and child elements below it:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template>
<xsl:template match="Characteristic"> <xsl:apply-templates/>
</xsl:template></xsl:stylesheet>

Thank You for your indulgence, I'm well aware that this question is pretty basic - I've ust run out of ideas..........
 
Old March 16th, 2011, 01:50 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Your input XML is in a namespace, therefore you need specify the namespace when matching against "Characteristic" element.

The first post in this forum contains a number of links to this very issue: Hints for a good XSLT post

Basically define your namespace, with a prefix, and then use the prefix in the match attribute.

Code:
<xsl:template xmlns:ns0="urn:cidx:names:specification:ces:schema:all:5:0" match="ns0:Characteristic" />
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
BobSSC (March 16th, 2011)
 
Old March 16th, 2011, 02:46 PM
Registered User
 
Join Date: Apr 2009
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Hi Sam -

No wonder I've been tearing my hair out over this! I'll certainly make a point of spending some time on Dave Pawson'a site - XML processing represents < 1% of what I do on a regular basis and I can't say I'm 'learning' it in the traditional sense. More trial and error than anything else.

Thank You for taking the time to reply - I appreciate the help!

Bob





Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding xml-html transformation of an xml string using xslt and javascript suprakash444 XSLT 1 January 12th, 2009 01:23 AM
How can I display parent & child nodes if XML .... vishnu108mishra ASP.NET 2.0 Basics 0 November 17th, 2007 07:45 AM
Copy parent node and not its children bonekrusher XSLT 4 August 29th, 2007 08:44 AM
merge two xml file and make new xml using xslt ketan XSLT 0 September 21st, 2004 08:48 AM
XML file w ith parent / child relationship bh0526 VB.NET 3 June 18th, 2003 08:28 AM





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