|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
DTD and XSLT for HTML Script Tag
I'm in the process of converting my web site from XHTML/CSS to XML/XSLT/CSS. I want to use a single XSLT template for all my XML docs. I can easily add JavaScripts to my XSLT template file, but I don't know how I can add different JavaScripts to my different XML documents, have the XML documents transformed and the JavaScripts work in the resulting documents.
I'm creating my own tags in my dtd, but they are pretty much based on HTML. My DTD excerpt for the script tag is as follows: <!ELEMENT script (#PCDATA)> <!ATTLIST script type CDATA #REQUIRED src CDATA #IMPLIED > I probably will only be referencing external JavaScripts, so I guess I could of done the following: <!ELEMENT script EMPTY> <!ATTLIST script type CDATA #REQUIRED src CDATA #REQUIRED> I think my first DTD would enable both inline JavaScript and external javascript files to be referenced, but I'm not sure. The XSLT code I have tried to use is: <xsl:template match="script"> <xsl:element name="script"> <xsl:attribute name="type"> <xsl:value-of select="@type"/> </xsl:attribute> <xsl:attribute name="src"> <xsl:value-of select="@src"/> </xsl:attribute> <xsl:comment>comment inserted for Internet Explorer</xsl:comment> <xsl:value-of select="."/> </xsl:element> </xsl:template> The <xsl:comment> is because someone mentioned that IE has problems with <script> </script> tags that have nothing in between them. Of course, my method doesn't work. I can't get my head round XSL, yet. I won't paste all of my xml,dtd and xslt file, because they are too big, but below is some code that may be relevant. The start of my xslt file: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0"> <xsl utput method="xml" indent="no" doctype-public="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"; doctype-system="-//W3C//DTD XHTML 1.0 Strict//EN" omit-xml-declaration="no" xml:space="preserve"/> <xsl:template match="/"> <html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en"> My current dtd for the script tag: <!ELEMENT script (#PCDATA)> <!ATTLIST script type CDATA #REQUIRED src CDATA #IMPLIED > Part of my XML document: <?xml version="1.0" encoding="utf-8" standalone="no"?> <?xml-stylesheet type="text/xsl" href="http://localhost/inc/xslt/general.xslt"?>; <!DOCTYPE awddoc SYSTEM "http://localhost/inc/dtd/general.dtd">; <awddoc> <head> <title>title</title> <script type="text/javascript" src="/inc/js/no_right_click.js"> </script> I'm a little confused about the use of CDATA sections. My external Javascript file contains //<![CDATA[ <!--// at the start of the script //--> //]]> at the end of the script The script I am using worked before I tried to convert to xml/xslt, so that is not an issue. Any help and/or pointers to specific tutorials on this issue would be most appreciated. Cheers |
|
#2
|
||||
|
||||
|
I am not quite sure if i pulled the exact question out of that but let me just tell you what I think.
It looks like you are sucessfully referrencing an external javascript file so my thought is that instead of having all these files to worry about referrencing you should have one common.js that is always called. Then within your common.js you have functions that perform certain actions. So, when you match a template you can wrap your javascript calls around the appropriate elements and receive the desired results. I hope this wasn't too far off since it is just my thoughts on methodology surrounding the subject.
__________________
mr... mike.rusaw@realpage.com RalPage, Inc. "I have made this letter longer than usual, only because I have not had the time to make it shorter." - Blaise Paschal |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > DTD and XSLT for HTML Script Tag |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|