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=" version="1.0">
<xslutput method="xml" indent="no" doctype-public=" doctype-system="-//W3C//DTD XHTML 1.0 Strict//EN" omit-xml-declaration="no" xml:space="preserve"/>
<xsl:template match="/">
<html xmlns=" 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="<!DOCTYPE awddoc SYSTEM "<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
The discipline used to write things down is the first step in making them a reality.
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=" version="1.0">
<xslutput method="xml" indent="no" doctype-public=" doctype-system="-//W3C//DTD XHTML 1.0 Strict//EN" omit-xml-declaration="no" xml:space="preserve"/>
<xsl:template match="/">
<html xmlns=" 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="<!DOCTYPE awddoc SYSTEM "<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
The discipline used to write things down is the first step in making them a reality.