Outputting a !DOCTYPE declaration from an XSL stylesheet
-
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 WebAs 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..."
-
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 anencoding="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..."
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
-
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
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..."
-
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..."
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
-
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
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"> <?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"> </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..."
-
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..."
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
-
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
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
-
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
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
-
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
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..."
-
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
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..."
-
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..."
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 theoutput
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 properoutput
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."