Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XMLNS issues with XSL transformation.

XMLNS issues with XSL transformation.

Scheduled Pinned Locked Moved XML / XSL
htmlxmlquestioncsharpwpf
3 Posts 2 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Domenic Denicola
    wrote on last edited by
    #1

    OK, I've got my source document, right? And it uses two different namespaces, my custom one and the XHTML one. The contents of it are a mix of XHTML and my own markup. So the header on that looks like this:

    <Page xmlns="/PageWriter/TemplateSchema.xsd" xmlns:XHTML="http://www.w3.org/1999/xhtml">

    Now, I've got my XSL stylesheet, right? And it's used to take the source document and transform it into pure XHTML. So I've figured out that I need to do this in my header, I think:

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:MHC="/PageWriter/TemplateSchema.xsd">

    <xsl:output	encoding="utf-8"
    		indent="yes"
    		doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
    		doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
    
    <xsl:template match="/">
    	<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
    

    And thereafter all references in my <xsl:...> tags that refer to my own custom elements use the prefix MHC:, like so:

    <title>MadHamster Creations - <xsl:value-of select="MHC:Page/MHC:Head/MHC:Title" /></title>

    BUT! The problem is now that I have a few weird output issues. The first of all, and this one is really bad because it makes my documents not validate as XHTML, is that my <html> tag now looks like this:

    <html xml:lang="en-US" lang="en-US" xmlns:MHC="/PageWriter/TemplateSchema.xsd" xmlns="http://www.w3.org/1999/xhtml">

    Not like this, which is how it's supposed to look but doesn't:

    <html xml:lang="en-US" lang="en-US" xmlns="http://www.w3.org/1999/xhtml">

    The other weird thing occurs only when I call a template from inside my main template, like so:

    <xsl:apply-templates select="MHC:Page/MHC:Body" />

    The header for the other template is:

    <xsl:template match="MHC:Page/MHC:Body" name="ProcessBody">

    Inside the main template, everything works fine. But when I call this other template, all of my XHTML elements generated inside that template have this extra attribute in them. The attribute is xmlns="", which is needless to say redundant, although it doesn't make the document invalid. Why? How can I stop it? Anyone who wants more in-depth information can get my source files and a .NET utility to transform them, by e-mailing me.

    W 1 Reply Last reply
    0
    • D Domenic Denicola

      OK, I've got my source document, right? And it uses two different namespaces, my custom one and the XHTML one. The contents of it are a mix of XHTML and my own markup. So the header on that looks like this:

      <Page xmlns="/PageWriter/TemplateSchema.xsd" xmlns:XHTML="http://www.w3.org/1999/xhtml">

      Now, I've got my XSL stylesheet, right? And it's used to take the source document and transform it into pure XHTML. So I've figured out that I need to do this in my header, I think:

      <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:MHC="/PageWriter/TemplateSchema.xsd">

      <xsl:output	encoding="utf-8"
      		indent="yes"
      		doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
      		doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
      
      <xsl:template match="/">
      	<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
      

      And thereafter all references in my <xsl:...> tags that refer to my own custom elements use the prefix MHC:, like so:

      <title>MadHamster Creations - <xsl:value-of select="MHC:Page/MHC:Head/MHC:Title" /></title>

      BUT! The problem is now that I have a few weird output issues. The first of all, and this one is really bad because it makes my documents not validate as XHTML, is that my <html> tag now looks like this:

      <html xml:lang="en-US" lang="en-US" xmlns:MHC="/PageWriter/TemplateSchema.xsd" xmlns="http://www.w3.org/1999/xhtml">

      Not like this, which is how it's supposed to look but doesn't:

      <html xml:lang="en-US" lang="en-US" xmlns="http://www.w3.org/1999/xhtml">

      The other weird thing occurs only when I call a template from inside my main template, like so:

      <xsl:apply-templates select="MHC:Page/MHC:Body" />

      The header for the other template is:

      <xsl:template match="MHC:Page/MHC:Body" name="ProcessBody">

      Inside the main template, everything works fine. But when I call this other template, all of my XHTML elements generated inside that template have this extra attribute in them. The attribute is xmlns="", which is needless to say redundant, although it doesn't make the document invalid. Why? How can I stop it? Anyone who wants more in-depth information can get my source files and a .NET utility to transform them, by e-mailing me.

      W Offline
      W Offline
      Wictor Wilen
      wrote on last edited by
      #2

      Heya, to get rid of the unnecessary XSL/XML info in your ouptut data then put the attribute 'exclude-result-prefixes' in the xsl:stylesheet node, like this: Just space-separate all the namespace prefixes you do not want in the result. I also set the 'omit-xml-declaration' to "yes" in the xsl:output element to get rid of the XML declaration. /WW

      D 1 Reply Last reply
      0
      • W Wictor Wilen

        Heya, to get rid of the unnecessary XSL/XML info in your ouptut data then put the attribute 'exclude-result-prefixes' in the xsl:stylesheet node, like this: Just space-separate all the namespace prefixes you do not want in the result. I also set the 'omit-xml-declaration' to "yes" in the xsl:output element to get rid of the XML declaration. /WW

        D Offline
        D Offline
        Domenic Denicola
        wrote on last edited by
        #3

        Thanks a ton for the response! I was beginning to think nobody knew... Anyways, the exclude-result-prefixes works great to get rid of the extra xmlns:MHC="..." in my <html> tag. I need to keep the XML declaration for valid XHTML however, but thanks for the help anyways. So, any ideas on the empty xmlns="" attribute that pops up in those elements? Rather weird... Thanks again, it's really reat to have someone who knows this stuff!

        -Domenic Denicola- [CPUA 0x1337] MadHamster Creations "I was born human. But this was an accident of fate - a condition merely of time and place. I believe it's something we have the power to change..."

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups