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 8th, 2009, 09:10 AM
Registered User
 
Join Date: Aug 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default copy-of select= not returning all elements

I'm trying to pull the complete XML (structure and data) from my input file and put into a string....

I am doing:

<string><xsl:copy-of select="ancestor-or-self::node()"/></string>

and it is not returning the complete structure.

I first do a: <xsl:template match="/">
then:
<xsl:copy-of select="ancestor-or-self::node()"/>

and the input XML is 9 lines long and the output will be 8. The root tag is missing from the output.

Why is my SELECT not returning the root node?

Is there a better way to do what I'm trying to do?

Thanks for any help...
Jack
 
Old August 8th, 2009, 09:14 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If the context node is the document root, then copy-of select="ancestor-or-self::node()" means the same as select="." and should copy the full tree. Perhaps your mistake is in the part of the code you haven't shown us?
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old August 8th, 2009, 09:16 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

If you have a template matching the root node (also called the document node) and want to copy the complete document then
Code:
<xsl:template match="/">
  <xsl:copy-of select="."/>
</xsl:tempate>
should suffice.
Consider to show us complete but minimal XML and XSLT samples demonstrating the problem.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old August 8th, 2009, 09:31 AM
Registered User
 
Join Date: Aug 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default copy-of select="." losing a tag

Here is my complete XSLT...

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>

The input XML is 9 lines long but the putput XML is onyl 8 lines long.
I'll post it just in case, I guess...
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
<soapenv:Body soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<bea:JaycService xmlns:bea="http://www.bea.com/servers/wls70/samples/examples/webservices/basic/statelessSession">
<string xsi:type="xsd:string">XDO267A61897</string>
</bea:JaycService>
</soapenv:Body>
</soapenv:Envelope>

The soapenv:Envelope line is missing from the output....
 
Old August 8th, 2009, 10:23 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I don't see anything wrong with that stylesheet. Which XSLT processor are you using? How exactly do you run the transformation? How do you look at the transformation result?
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old August 8th, 2009, 10:36 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Also how exactly does the wrong output look? Your current description sounds as if the soapenv:Envelope start tag is missing while the end tag is there. Is that really the case? An XSLT processor builds a result tree and serializes that so unless the serialization fails it is not possible that the result is not well balanced.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old August 8th, 2009, 10:45 AM
Registered User
 
Join Date: Aug 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reply with output XML

Here is the output XML...
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
<soapenv:Body soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<bea:RouterService xmlns:bea="http://www.bea.com/servers/wls70/samples/examples/webservices/basic/statelessSession">
<string xsi:type="xsd:string">XDO267A61897</string>
</bea:RouterService>
</soapenv:Body>
</soapenv:Envelope>

As you can see, the envelope tag is missing but the endign tag is there.

I am using Oxygen XSL Editor to write this.

If someone uses a different editor or parser, does this code work for them? I have been trying to figure out why that code didin't work for two days now...!!!
 
Old August 8th, 2009, 10:53 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

The output you have posted has an <soapenv:Envelope ...> start tag right after the XML declaration so I am not sure why you say it is missing. The only thing that has changed from the input is the line break between the XML declaration and the root element but that is quite normal as the XML declaration is not part of the XSLT/XPath data model. Rather it is added to the result by the serializer. If you want a line break use
Code:
<xsl:output method="xml indent="yes"/>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old August 8th, 2009, 01:38 PM
Registered User
 
Join Date: Aug 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default OMG I AM STUPID!

I Apologize for wasting your time along with mine. I had this new "perspective" up in my editor and it concatenated things...

Everything works just like it should... Thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning elements. Neal XSLT 2 May 13th, 2007 04:38 PM
Returning the 1st row of a SELECT Sub Query rit01 SQL Server 2000 2 February 21st, 2006 12:20 PM
How to remove all elements of select in JavaScript Edward King Javascript How-To 1 August 14th, 2004 05:11 AM
Returning Oracle SELECT query results to DataSet gp_mk ADO.NET 0 December 17th, 2003 11:08 AM
Select distinct elements andrin XSLT 2 August 4th, 2003 04:07 AM





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