| re: Using XSLT to extend XHTML
Eric Anderson wrote:[color=blue]
> I am trying to use XSLT to extend XHTML so that I can have custom
> widgets. For example I have a calendar control. Whenever I put the
> following in the psudo-XHTML doc:
>
> <calendarbox name="mycal"/>
>
> I get a nice xhtml text box with a calendar icon beside it. When the
> calendar icon is clicked a calender pops up to allow the user to choose
> the date. Then the value chosen is stuck in the xhtml text field and can
> be submitted with the form. I have this working quite well but I have
> one problem. My general strategy has been to have my xhtml doc call a
> similarly named xsl file. This xsl file imports some general xsl
> templates and also imports some xsl templates for specific functionality
> used in the xhtml doc. Now some of the imported xsl templates may need
> to add stylesheet and script tags to the xhtml head tag. How do I add
> this information while still allowing other templates to add their style
> and script tags. Let me give you a simplified example:
>
> foo.xhtml
> ---------
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <?xml-stylesheet type="text/xsl" href="/structure/foo.xsl"?>
>
> <html>
> <head>
> <title>My title</title>
> <link rel="stylesheet" type="text/css" href="/style/foo.css"/>
> </head>
> <body>
> <specialwidget/>
> </body>
> </html>
>
> foo.xsl
> -------
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns="http://www.w3.org/1999/xhtml">
>
> <xsl:import href="general.xsl"/>
> <xsl:import href="widgets.xsl"/>
> <xsl:import href="site.xsl"/>
>
> </xsl:stylesheet>
>
> First thing to note is that foo.xhtml could have style and script
> information itself. The second thing to note is that any of the imported
> xsl files in foo.xsl could add style and script information that their
> custom widgets might need.
>
> My goal is to encapsulate the external dependencies that each imported
> xsl file needs so that all I have to do is import the xsl file. The
> imported style will take care of adding those dependencies to the header.
>
> Any suggestions?
>
> Eric
>[/color]
You should use a namespace for your controls:
like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="/structure/foo.xsl"?>
<html xmlns:widgets="http://www.yourpage.com/namespace">>
<head>
<title>My title</title>
<link rel="stylesheet" type="text/css" href="/style/foo.css"/>
</head>
<body>
<widgets:specialwidget/>
</body>
</html>
And your xsl could match widges:specialwidget
Hope you understand. Learn more about namespaces too, its really cool |