Subject: namespaces appearing in tags after XSL translation
Posted By: mphare Post Date: 2/20/2006 11:47:12 AM
When I translate and XML file that defines namespaces, I get the namespaces showing up in HTML tags. ? ?

I'm using Saxon 8B and Oxygen 7.0

I've created a small XML and XSLT file to show the problem:

XML File:
<?xml version="1.0" encoding="UTF-8"?><?mso-application progid="Excel.Sheet"?>
<Workbook 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    
    <Cell>Inside the Cell 1</Cell>
    <Cell>Inside the Cell 2</Cell>
</Workbook>


The XSLT File:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <!-- 
    ****************************************************
    -->
    <!-- Begin Output Processing -->

    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/Workbook">
        <xsl:text>Found Workbook</xsl:text>
        <xsl:apply-templates select="Cell"></xsl:apply-templates>
    </xsl:template>
    
    <!-- 
    ****************************************************
    Template for Cell
    ****************************************************
    -->
    <xsl:template match="Cell">
        <br/><xsl:text>Inside the Cell</xsl:text>
    </xsl:template>
    
    
</xsl:stylesheet>


And finally the output:
<?xml version="1.0" encoding="UTF-8"?>Found Workbook<br xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>Inside the Cell<br xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>Inside the Cell


Notice the translated <br/> tags.. they have the xsi namespace declaration appearing inside the tags.

What's up with that?


------------------------
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF&nbsp;&nbsp;ACE5 CA93 7AD5 D8E3 A876

Michael Hare
Reply By: mphare Reply Date: 2/20/2006 11:51:05 AM
OK, got the answer, never mind
needed 'exclude-result-prefixes'




------------------------
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF&nbsp;&nbsp;ACE5 CA93 7AD5 D8E3 A876

Michael Hare
Reply By: mhkay Reply Date: 2/20/2006 12:09:38 PM
You're not using the xsi namespace in your stylesheet, so why declare it?

If you do need to declare a namespace in your stylesheet that you don't want copied into the result tree, use exclude-result-prefixes to suppress it.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply By: mphare Reply Date: 2/20/2006 1:26:41 PM
This is (obviously) the first time I've needed to deal with namespaces in the XML document I'm translating.
The document I'm using comes from Excel 2003 and defines 5 or 6 namespaces and they are all used in the complete document.
My example above was a paired back example in an attempt to show my problem.

I'm sure I'm asking a loaded question, I have read the 1.0 version of your book, but I don't see the reason why these
namespaces show up in such a (seemingly) bizarre place as the end of html tags.

Anyway

exclude-result-prefixes works so I'm back to work translating my documents.

Thanks for responding and thanks for the great book!

------------------------
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF&nbsp;&nbsp;ACE5 CA93 7AD5 D8E3 A876

Michael Hare
Reply By: mhkay Reply Date: 2/20/2006 2:49:22 PM
There's a rule in XSLT that when you write a literal result element in the stylesheet, it gets copied to the result document along with all its in-scope namespaces other than any excluded namespaces. The main reason for this is that the system can't tell which of the namespaces are needed and which aren't, so it's safer to copy them all.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

Go to topic 40239

Return to index page 365
Return to index page 364
Return to index page 363
Return to index page 362
Return to index page 361
Return to index page 360
Return to index page 359
Return to index page 358
Return to index page 357
Return to index page 356