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. Outputting a !DOCTYPE declaration from an XSL stylesheet

Outputting a !DOCTYPE declaration from an XSL stylesheet

Scheduled Pinned Locked Moved XML / XSL
xmlquestionlearninghtmlcom
21 Posts 4 Posters 87 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.
  • M Michael A Barnhart

    Yes I did not check the display message as is (no HTML). :-O I was just adding the xsl:text tag that essam mentions above. There are also option to not add all of the text (line feeds etc.) to the output. My Sample lines were approximately: #VRML V2.0 utf8 # [X3D] VRML V3.0 utf8 This is the begining of my translation file for converting X3D models into VRML97. Lets see if I get it right this time. There are a number of sites with info here. One example is the w3schools site http://www.w3schools.com/xsl/el\_text.asp and zvon http://www.zvon.org/xxl/XSLTreference/W3C/xslt.html#element-text both on the partners links on CP. To be conscious that you are ignorant of the facts is a great step towards Knowledge. Benjamin Disraeli

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

    This works great! Thank you so much! But now I've got another question... Should I do the same thing for my <?xml version="1.0" encoding="utf-8"?> that I want at the very top of the output document, or will this be done for me? From what I've seen using XSL Tester to view my XHTML output, this is done for me, but it gives me an encoding="UTF-16", which I don't think is a valid encoding. Can I somehow change the way this is generated automatically if it is, or is this simply a quirk in XSL Tester and I should do the same thing Idid with my !DOCTYPE, by putting it in that special <xsl:tex> element?

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

    M 1 Reply Last reply
    0
    • E Erik Westermann

      Domenic [CPUA 0x1337] wrote: Any other suggestions? Yes - I forgot to mention that you need to enclose the modified DOCTYPE declaration within an xsl:text element, as follows (assuming that the XSL's namespace prefix is xsl): <xsl:text disable-output-escaping="yes"> <!DOCTYPE html...> </xsl:text> That should work - famous last words... Essam - Author, JScript .NET Programming
      ...and a bunch of articles around the Web

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

      As I said on the below thread, this works great, thanks a ton! I do have another question tho, but I would refer you to the below thread, as I don't know how long I can keep this multi-threading going!

      -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
      • D Domenic Denicola

        This works great! Thank you so much! But now I've got another question... Should I do the same thing for my <?xml version="1.0" encoding="utf-8"?> that I want at the very top of the output document, or will this be done for me? From what I've seen using XSL Tester to view my XHTML output, this is done for me, but it gives me an encoding="UTF-16", which I don't think is a valid encoding. Can I somehow change the way this is generated automatically if it is, or is this simply a quirk in XSL Tester and I should do the same thing Idid with my !DOCTYPE, by putting it in that special <xsl:tex> element?

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

        M Offline
        M Offline
        Michael A Barnhart
        wrote on last edited by
        #12

        I assume that you are using one of the MSXML implementations. To set the encoding see the xsl:output transformation element (at the begining of the transformation), You should be able to set utf-8 with it. UTF-16 is a valid encoding. Most of my work right now is with the Apache line of implementations so there may be some variations. I have shown that DOM and SAX transformations do not always give the same results. I do have some test applications with the MSXML v3 and v4 so I can do some experiments if needed. To be conscious that you are ignorant of the facts is a great step towards Knowledge. Benjamin Disraeli

        D 1 Reply Last reply
        0
        • M Michael A Barnhart

          I assume that you are using one of the MSXML implementations. To set the encoding see the xsl:output transformation element (at the begining of the transformation), You should be able to set utf-8 with it. UTF-16 is a valid encoding. Most of my work right now is with the Apache line of implementations so there may be some variations. I have shown that DOM and SAX transformations do not always give the same results. I do have some test applications with the MSXML v3 and v4 so I can do some experiments if needed. To be conscious that you are ignorant of the facts is a great step towards Knowledge. Benjamin Disraeli

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

          I am using the MSXSL that comes with IE6 or the .NET Runtime, whichever is newer (I have both installed). So XSL will generate an <?xml...?> declaration automagically, which can be controlled by the <xsl:output> element?

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

          M 1 Reply Last reply
          0
          • D Domenic Denicola

            I am using the MSXSL that comes with IE6 or the .NET Runtime, whichever is newer (I have both installed). So XSL will generate an <?xml...?> declaration automagically, which can be controlled by the <xsl:output> element?

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

            M Offline
            M Offline
            Michael A Barnhart
            wrote on last edited by
            #14

            I can say that the xml declaration is not allways output. With the output line shown earlier it should never be output. Just add it with the xsl:text line if needed. The output line will set if encoding is utf-8. To be conscious that you are ignorant of the facts is a great step towards Knowledge. Benjamin Disraeli

            D 1 Reply Last reply
            0
            • M Michael A Barnhart

              I can say that the xml declaration is not allways output. With the output line shown earlier it should never be output. Just add it with the xsl:text line if needed. The output line will set if encoding is utf-8. To be conscious that you are ignorant of the facts is a great step towards Knowledge. Benjamin Disraeli

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

              So, my XSL should like like this:

              <?xml version="1.0" encoding="utf-8"?>

              <xsl:stylesheet version="1.0">

              <xsl:output encoding="utf-8" />
              <xsl:template match="/">
              	<xsl:text disable-output-escaping="yes">
              		&lt;?xml version="1.0" encoding="utf-8"?&gt;
              		&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
              
              	</xsl:text>
              
              	<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
              		<!-- Stuff here -->
              	</html>
              </xsl:template>
              

              </xsl:stylesheet>

              And this will output:

              <?xml version="1.0" encoding="utf-8"?>
              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

              <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
              <!-- The stuff that was where the comment was goes here -->
              </html>

              If you're not absolutely sure, could you write me quick program or give me the JScript code (not .NET) to just output the text? Whenever I do a view source in IE, it just gives me the original XML. I would do that myself, but I'm stuck on this Windows 98 until I get a new hard drive :( Thank you!

              -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
              • D Domenic Denicola

                This has been driving me crazy! I am trying to use XSL to output a nice pretty XHTML page from my XML feed. And of course, all nice pretty XHTML pages include a !DOCTYPE declaration. But whenever I try and simply stick it in my tag, it gives me this error: **Cannot have a DOCTYPE declaration outside of a prolog. Error processing resource 'file:///C:/Inetpub/wwwroot/PageWriter/Template.xsl'. Line 13, Position 13** ------------^ I've tried a variety of things, such as splitting up the !DOCTYPE into various pieces and putting them in elements, but that didn't work. Anybody know the answer? This must be a fairly common question, not all XHTML and HTML outputs can be sloppily tossed out w/o a !DOCTYPE (i.e. like they are in all examples I can find).

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

                P Offline
                P Offline
                Paul Watson
                wrote on last edited by
                #16

                There are two ways to output the DOCTYPE. One is using the OUTPUT method in XSL, like so:

                >xsl:output method="html" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="DTD/xhtml1-transitional.dtd" indent="yes" /<

                The other, is easier but probably not such a good idea. It uses the XSL:TEXT and CDATA section methods:

                >xsl:text disable-output-escaping="yes"<>![CDATA[>!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"<]]<>/xsl:text<

                This one also baffled me for awhile until I found the OUTPUt method, happy hunting. regards, Paul Watson Bluegrass Cape Town, South Africa The greatest thing you'll ever learn is just to love, and to be loved in return - Moulin Rouge

                M D 3 Replies Last reply
                0
                • P Paul Watson

                  There are two ways to output the DOCTYPE. One is using the OUTPUT method in XSL, like so:

                  >xsl:output method="html" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="DTD/xhtml1-transitional.dtd" indent="yes" /<

                  The other, is easier but probably not such a good idea. It uses the XSL:TEXT and CDATA section methods:

                  >xsl:text disable-output-escaping="yes"<>![CDATA[>!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"<]]<>/xsl:text<

                  This one also baffled me for awhile until I found the OUTPUt method, happy hunting. regards, Paul Watson Bluegrass Cape Town, South Africa The greatest thing you'll ever learn is just to love, and to be loved in return - Moulin Rouge

                  M Offline
                  M Offline
                  Michael A Barnhart
                  wrote on last edited by
                  #17

                  Paul, Nice to see you back. I hope this is not temporary. To be conscious that you are ignorant of the facts is a great step towards Knowledge. Benjamin Disraeli

                  P 1 Reply Last reply
                  0
                  • M Michael A Barnhart

                    Paul, Nice to see you back. I hope this is not temporary. To be conscious that you are ignorant of the facts is a great step towards Knowledge. Benjamin Disraeli

                    P Offline
                    P Offline
                    Paul Watson
                    wrote on last edited by
                    #18

                    Thanks Michael, it is semi-temporary. I have not been off of CP voluntarily, but rather I have been at the mercy of my internet connection which deems CP an unforgivingly slow site. However our new line should be in within the week and I shall be back next week. I miss the place :) regards, Paul Watson Bluegrass Cape Town, South Africa The greatest thing you'll ever learn is just to love, and to be loved in return - Moulin Rouge

                    1 Reply Last reply
                    0
                    • P Paul Watson

                      There are two ways to output the DOCTYPE. One is using the OUTPUT method in XSL, like so:

                      >xsl:output method="html" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="DTD/xhtml1-transitional.dtd" indent="yes" /<

                      The other, is easier but probably not such a good idea. It uses the XSL:TEXT and CDATA section methods:

                      >xsl:text disable-output-escaping="yes"<>![CDATA[>!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"<]]<>/xsl:text<

                      This one also baffled me for awhile until I found the OUTPUt method, happy hunting. regards, Paul Watson Bluegrass Cape Town, South Africa The greatest thing you'll ever learn is just to love, and to be loved in return - Moulin Rouge

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

                      The output works GREAT for the !DOCTYPE, and is much preferable to the method I got from above (enclosing it in a <xsl:text disable-output-escaping="yes"> section) But... I'm still stuck on getting my <?xml...?> into the output, as I am really trying to output XHTML, not HTML as the above <xsl:output> you posted says (and all good XHTML has a <?xml...?> declaration, as it is XML). Will this automagically appear, with the encoding specified in the <xsl:output> tag? Or do I have to put it in a <xsl:text disable-output-escaping="yes"> tag? Again, I could figure this all out myself without bugging everyone if someone would just write a program that takes in.xml, and using transform.xsl outputs out.xsl. That's all I need! I have one that is supposed to do this called XSL Tester, but it's rather screwy (always outputting a <?xml version="1.0" encoding="UTF-16"?> at the top, no matter what I do with output or text tags.), and doesn't use the .NET version of MSXML so I'm never sure if that's really what's going to happen. Heck, I could send you the source code if you would compile it! Thank you for your time and help,

                      -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
                      • P Paul Watson

                        There are two ways to output the DOCTYPE. One is using the OUTPUT method in XSL, like so:

                        >xsl:output method="html" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="DTD/xhtml1-transitional.dtd" indent="yes" /<

                        The other, is easier but probably not such a good idea. It uses the XSL:TEXT and CDATA section methods:

                        >xsl:text disable-output-escaping="yes"<>![CDATA[>!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"<]]<>/xsl:text<

                        This one also baffled me for awhile until I found the OUTPUt method, happy hunting. regards, Paul Watson Bluegrass Cape Town, South Africa The greatest thing you'll ever learn is just to love, and to be loved in return - Moulin Rouge

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

                        Actually, now I have a working solution, but I'm getting the idea it's bad practice, and wanted to know if it is. I enclose EVERYTHING in a:

                        xsl:text
                        <!CDATA[[
                        <!-- There's a bunch of XHTML here,
                        including the xml processing instruction and the
                        DOCTYPE, but it's parsed as simply text. Is
                        this good practice? Because it's convenient! -->
                        ]]>
                        </xsl:text>

                        section. It works, and it's very convienient. Whenever I want to output something using template rules, I simply end if with a ]]></xsl:text>, write the xsl element, then restart it with the <xsl:text><!CDATA[[. But... this just seems kind of wrong... but it works... but it seems wrong... but... so, what do you think?

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

                        P 1 Reply Last reply
                        0
                        • D Domenic Denicola

                          Actually, now I have a working solution, but I'm getting the idea it's bad practice, and wanted to know if it is. I enclose EVERYTHING in a:

                          xsl:text
                          <!CDATA[[
                          <!-- There's a bunch of XHTML here,
                          including the xml processing instruction and the
                          DOCTYPE, but it's parsed as simply text. Is
                          this good practice? Because it's convenient! -->
                          ]]>
                          </xsl:text>

                          section. It works, and it's very convienient. Whenever I want to output something using template rules, I simply end if with a ]]></xsl:text>, write the xsl element, then restart it with the <xsl:text><!CDATA[[. But... this just seems kind of wrong... but it works... but it seems wrong... but... so, what do you think?

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

                          P Offline
                          P Offline
                          Paul Watson
                          wrote on last edited by
                          #21

                          Domenic [_Geek_n] wrote: But... this just seems kind of wrong... but it works... but it seems wrong... but... so, what do you think? It works, just like using pantyhose to fix a broken fan-belt in a car works. However as soon as you can you should get a new proper fan-belt, right? I had a crushing deadline which forced me to use the xsl:text method to output the DOCTYPE. However what happened was that when a third party tried to programatically query my XSL documents to gather some info for an integration project they failed to get the DOCTYPE. I eventually re-coded my XSL docs to use the output method. So the answer is; Yes it works but don't do it if you can avoid it. Your XSL docs will be technically better and easier to maintain in the future if you use the proper output method. regards, Paul Watson Bluegrass Cape Town, South Africa The greatest thing you'll ever learn is just to love, and to be loved in return - Moulin Rouge "Reports of my death have been greatly exaggerated."

                          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