I was testing out XSLT identity transform and so I randomly chose the following example on www.w3schools.com because it allows me to try online:
http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog_apply
I changed the XSLT in the right pane to be identity transform:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
And tried it out. What I found was that the /catalog/cd/title
nodes do not get copied into the output (but everything else does). If I change the name from /catalog/cd/title
to /catalog/cd/title1
(or any other name) it does copy the node.
So I was wondering if there is just a bug in the XSLT implementation on www.w3schools.com or if there is some special significance to the XML node 'title' that causes it to not get copied? I'm planning on using the XSLT transform as described above, but I want to make sure I'm aware of any gotchas...
That w3schools tool is useful for testing XML to HTML transformation as it tries to render the transformation result as HTML in the browser. With your identity transformation you do not create any HTML but rather XML. Only the "title" element in the transformation result looks to the browser as a known but wrongly placed HTML element so it does not display it in the page. All other elements are unknown so their text contents is rendered.
Basically get yourself a standalone XSLT processor or an XML editor, that w3schools tool is not useful to debug and test anything but XML to HTML transformations.
It works fine using xsltproc on Debian.
Update: works too using saxon-xlst…
The problem should be with the W3C School implementation…
Update after Martin's answer: uh… No problem but only xml to html conversion… Time for me to halt for the day? ;)
I can't reproduce your result, but it may be browser-dependent. What you have overlooked is that the page is rendering the result of the transformation as if it were HTML, which in your case it isn't. Exactly what browsers do with XML that uses non-HTML tags is likely to be unpredictable.
I know it is old post, but I did not see the correct answer here.
<xsl:copy>
Namespace nodes of the current node are automatically copied as well, but child nodes and attributes of the current node are not automatically copied!
<xsl:copy-of>
Namespace nodes, child nodes, and attributes of the current node are automatically copied as well!