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 24th, 2011, 01:42 PM
Authorized User
 
Join Date: May 2007
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default Random xmlns="" in output

I have one more question that I am unable to resolve. I am finding empty xmlns attributes in my output:

<content xmlns="">
<item type="dummy">
test
</item>
</content>

This seems to happen for any outermost element defined by its own template:

<xsl:template match="content">
<content>
<item type="{@itemType}"><xsl:value-of select="."></item>
</content>
</xsl:template>

Please note that it doesn't add the xmlns to the <item> element, only the <content> element.
 
Old February 24th, 2011, 01:46 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Well you haven't shown any of your XSLT code but I suspect you can fix the issue by putting
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="yourTargetNamespaceGoesHere"
  version="1.0">

</xsl:stylesheet>
into your stylesheet's root element.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old February 24th, 2011, 02:03 PM
Authorized User
 
Join Date: May 2007
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I omitted the stylesheet because it is quite long, I have shortened it for this example.

My issue is that I don't want the namespace (xmlns="") at all.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:saxon="http://saxon.sf.net/"
exclude-result-prefixes="xs saxon"
version="2.0">

<xsl:output method="xml" indent="yes" cdata-section-elements="description" name="xml"/>

<xsl:template match="/">
<xsl:apply-templates select="product">
</xsl:template>

<xsl:template match="product">

<xsl:result-document format="xml" href="{@id}/out.xml">
<xsl:apply-templates select="content"/>
</xsl:result-document>

</xsl:template>

<xsl:template match="content">
<content>
<item type="{@itemType}"><xsl:value-of select="."></item>
</content>
</xsl:template>

</xsl:stylesheet>
 
Old February 24th, 2011, 02:15 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I can't tell what goes wrong with that stylesheet sample alone. Post enough information allowing us to reproduce the problem (i.e. input sample, XSLT processor version). Usually the problem occurs when people want to output XHTML for instance and then do it like this
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:template match="/">
     <html xmlns="http://www.w3.org/1999/xhtml">
        <body>
           <xsl:apply-templates/>
        </body>
     </html>
  </xsl:template>

  <xsl:template match="foo">
     <p>
       <xsl:apply-templates/>
     </p>
   </xsl:template>

</xsl:stylesheet>
as that way the "p" elements are created in no namespace inside of a "body" elements in the XHTML namespace and then the output has <p xmlns="">...</p> to ensure the "p" elements are output in no namespace. Moving the xmlns="http://www.w3.org/1999/xhtml" to the stylesheet root fixes that problem.

I don't see anything like that in your stylesheet sample so I am not sure why you get the xmlns="" in your output.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old February 24th, 2011, 02:19 PM
Authorized User
 
Join Date: May 2007
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Martin,

That was my problem and adding the namespace to the stylesheet element solved it. Thank you for your help.





Similar Threads
Thread Thread Starter Forum Replies Last Post
MSXSL gives error message for "for" inside "select" ilyaz XSLT 1 December 9th, 2010 05:02 PM
Removing whitespace from "text" output baseliner XSLT 8 November 24th, 2010 07:50 AM
"xmlns" not allowing to work [email protected] XSLT 2 July 30th, 2010 08:56 AM
How to theme the "Browse" button of "FileUpload" control? varunbwj BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 October 14th, 2009 01:22 AM
Add a CheckBox DataColumn to my DataGridView, Null format: "" or "True" but Error: F ismailc C# 2005 0 September 25th, 2009 04:56 AM





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