[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] XHTML to XHTML transform


Subject: Re: [xsl] XHTML to XHTML transform
From: "Jeff Moss" <jeff@xxxxxxxxxxxx>
Date: Fri, 2 Apr 2004 20:29:10 -0700

Robert,

Not sure what you meant with the upper to lowercase conversion routines.

My source XML contains XHTML tags, and I want those to end up in the
results, no transform at all, and templates applied to any unrecognized
tags, or else they're removed (including text nodes).

The solution I came up with is to put all my custom tags, like "box" and
"navtree" in their own namespace, and in order for text nodes to be removed,
I had to define an empty template for them matching my custom namespace.
HTML text elements need to be passed through (default behavior).

My goal is to replace php's smarty template engine with something clean,
simple and flexible. I'm surprised it works out so well. I'm also surprised
nobody has thought of this sooner. The newly released PHP5 comes with the
ability to embed a php function anywhere in your XSL stylesheet, given that
you "registered" the function into the processor beforehand.

Now I can do things like:

<html>
 <body>
  <template:box color="red">
   <template:header>Link List</template:header>
   <template:link-list />
  </template:box>
 </body>
</html>

<template:link-list /> maps into a <xsl:for-each
select="php:function(getList)">

Looks fabulous to me! I also have a separate namespace defined for elements
I want processed at runtime, template is all done at "compile" time. I am
very impressed at how well this all works out!

If you have any suggestions I'm all ears. :)

-Jeff

----- Original Message -----
From: "Robert Koberg" <rob@xxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, April 02, 2004 6:58 PM
Subject: Re: [xsl] XHTML to XHTML transform


> This thread seems very strange... Or perhaps the subject line is simply
> wrong. No one seems to be talking about XHTML (it requires lowercase
> tags...). I provided a relatively complete answer to the problem but
> people (and the original poster) seem to be trying to make it more
> difficult than it is. I don't get it...
>
> -Rob
>
>
> >>-----Original Message-----
> >>From: Jeffrey Moss [mailto:jeff@xxxxxxxxxxxx]
> >>Sent: 02 April 2004 21:55
> >>To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> >>Subject: Re: [xsl] XHTML to XHTML transform
> >>
> >>How do I match text nodes in my custom namespace? As in
> >>override the default
> >>text node template for "mynamespace"?
> >>
> >>All my variables <mynamespace:name>blah</mynamespace:name>
> >>for instance
> >>appear as text in the results, I've tried this:
> >>
> >><xsl:template match="text()[namespace-uri()='mynamespace:namespace']">
> >></xsl:template>
> >>
> >>but that doesn't work... I ended up changing all the elements
> >>I want hidden
> >>under all circumstances to the mynamespace-var namespace...
> >>
> >><xsl:template match="*[namespace-uri()='mynamespace-var:namespace']">
> >></xsl:template>
> >>
> >>This works, but I think its messy, I was wondering if there
> >>was a better
> >>way? I'm pasting my code below.
> >>
> >>Thanks,
> >>
> >>-Jeff
> >>
> >>
> >>
> >><?xml version="1.0" encoding="ISO-8859-1"?>
> >><xsl:stylesheet version="1.0"
> >>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> >>  xmlns:nbn="nbn:namespace"
> >>  xmlns:nbn-run="nbn-run:namespace"
> >>  xmlns:nbn-var="nbn-var:namespace"
> >>  exclude-result-prefixes="nbn nbn-run nbn-var">
> >><xsl:param name="controller" select="'index.php'"/>
> >><xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
> >>
> >><xsl:template match="/sitemap">
> >>  <DIV CLASS="navtree">
> >>    <xsl:apply-templates />
> >>  </DIV>
> >></xsl:template>
> >>
> >><xsl:template match="*[not(namespace-uri())]">
> >>  <xsl:copy>
> >>    <xsl:apply-templates />
> >>  </xsl:copy>
> >></xsl:template>
> >>
> >><xsl:template match="text()">
> >></xsl:template>
> >>
> >><xsl:template match="*[namespace-uri()='nbn-var:namespace']">
> >></xsl:template>
> >>
> >><xsl:template match="nbn:link">
> >>  <xsl:element name="A">
> >>    <xsl:attribute name="HREF">/<xsl:value-of
> >>select="$controller"/>/module/<xsl:value-of
> >>select="nbn-var:location/nbn-var:module" />/action/<xsl:value-of
> >>select="nbn-var:location/nbn-var:action" />/</xsl:attribute>
> >>    <xsl:attribute name="ID"><xsl:value-of
> >>select="@id"/></xsl:attribute>
> >>    <xsl:attribute name="CLASS">menuitem</xsl:attribute>
> >>    <xsl:value-of select="@name"/>
> >>  </xsl:element>
> >>  <xsl:apply-templates />
> >>  <BR/>
> >>  <xsl:if test="link">
> >>    <xsl:element name="DIV">
> >>      <xsl:attribute name="CLASS">submenu</xsl:attribute>
> >>      <xsl:apply-templates select="link"/>
> >>    </xsl:element>
> >>  </xsl:if>
> >></xsl:template>
> >>
> >></xsl:stylesheet>


Current Thread
Keywords