Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT identity transform

Tags:

xml

xslt

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...

like image 590
Kevin Avatar asked May 24 '26 17:05

Kevin


1 Answers

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.

like image 90
Martin Honnen Avatar answered May 27 '26 08:05

Martin Honnen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!