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 February 20th, 2006, 12:47 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default namespaces appearing in tags after XSL translation

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:
Code:
<?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:
Code:
<?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">
    <!-- 
    ****************************************************
    -->


    <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:
Code:
<?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
__________________
------------------------
Keep Moving Forward

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

Michael Hare
 
Old February 20th, 2006, 12:51 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

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
 
Old February 20th, 2006, 01:09 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old February 20th, 2006, 02:26 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

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
 
Old February 20th, 2006, 03:49 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
html tags to reformed to xhtml standard using xsl swapbpl XSLT 12 May 8th, 2008 05:38 AM
XSL:FO Querying block id tags goldendase XSLT 4 September 20th, 2007 02:54 PM
XSL containing JSTL tags! techfreak123 XSLT 5 August 1st, 2006 09:50 PM
Unicode translation using [xsl:output-character] ROCXY XSLT 5 May 15th, 2006 12:19 PM
Removing Namespaces from XSL Transform output francislang XSLT 2 September 7th, 2004 07:58 AM





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