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 May 11th, 2013, 07:36 PM
Registered User
 
Join Date: Nov 2011
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default XSLT Function to exclude Parent Element

Hello,

This might sound simple to experts in the forum, but would really appreciate if somebody can help me.

Input

<VehicleLookupOut>
<ReturnCode>?</ReturnCode>
<Reg>?</Reg>
<Make>?</Make>
<Model>?</Model>
<Mark>?</Mark>
<Year>?</Year>
<IntCode>?</IntCode>
<ManufactureYear>?</ManufactureYear>
</VehicleLookupOut>

Desired Output

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://directlinegroup.co.uk/schemas/webservice/common/header/external/1/0/" xmlns:ns1="http://directlinegroup.co.uk/schemas/vehicle/lookup/in/businessentity/1/0/" xmlns:dpm="http://www.datapower.com/schemas/management" xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</soapenv:Header>
<soapenv:Body>
<ns1:VehicleLookupOut>
<VehicleLookupResponse>
<ReturnCode>?</ReturnCode>
<Reg>?</Reg>
<Make>?</Make>
<Model>?</Model>
<Mark>?</Mark>
<Year>?</Year>
<IntCode>?</IntCode>
<ManufactureYear>?</ManufactureYear>
</VehicleLookupResponse>
</ns1:VehicleLookupOut>
</soapenv:Body>
</soapenv:Envelope>

Under VehicleLookupResponse, I need the entire XML response to be copied as i will be hardcoding elements <ns1:VehicleLookupOut> and <VehicleLookupResponse> in XSLT. I've tried using <xsl:copy-of select="."/> but the entire context node is getting copied which means <VehicleLookupOut> element is getting repeated in the response. So i will have to exclude the parent element while reading the response.

Please could you help me?
 
Old May 12th, 2013, 05:00 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Well you haven't posted your XSLT, if the copy-of select="." copies the VehicleLookupOutput and you don't want that then using
Code:
<xsl:copy-of select="node()"/>
to copy only the child nodes of the context node (which seems to be the VehicleLookupOutput) should do what you want, or perhaps
Code:
<xsl:copy-of select="*"/>
to copy all child elements.
As an alternative use
Code:
<xsl:stylesheet
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:ns="http://directlinegroup.co.uk/schemas/webservice/common/header/external/1/0/"   xmlns:ns1="http://directlinegroup.co.uk/schemas/vehicle/lookup/in/businessentity/1/0/"  xmlns:dpm="http://www.datapower.com/schemas/management"  xmlns:env="http://www.w3.org/2003/05/soap-envelope"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

<xsl:template match="/">
<soapenv:Envelope>
<soapenv:Header>
  </soapenv:Header>
   <soapenv:Body>
          <xsl:apply-templates/>
   </soapenv:Body>
</soapenv:Envelope>
</xsl:template>

<xsl:template match="@* | node()">
  <xsl:copy>
     <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="VehicleLookupOutput">
<ns1:VehicleLookupOut>
         <VehicleLookupResponse>
               <xsl:apply-templates/>
         </VehicleLookupResponse>
      </ns1:VehicleLookupOut>
</xsl:template>

</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT Exclude Parent and children from XML BobSSC XSLT 2 March 16th, 2011 02:46 PM
Value of parent element of current-grouping-key() bonekrusher XSLT 2 September 9th, 2007 06:29 AM
Can I promote an element by not copying a parent? dmorin XSLT 1 August 9th, 2006 03:52 PM
How to delete an element and parent node. crossedge XSLT 1 March 14th, 2006 05:10 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.