Subject: Re: [xsl] Trouble with namespaces and running identity transform on XHTML From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Wed, 10 Mar 2004 11:36:11 -0500 |
<xsl:template match="h:h1|h:h2|h1|h2"> <p> LOOK MA! <xsl:apply-templates select="@*|node()"/> NO BRAINS! </p> </xsl:template>
Cheers, Wendell When there is no such
I've been working on a stylesheet to "massage" some XHTML. One variation of a test stylesheet is here:
<xsl:transform xmlns:h="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
<xsl:output method="xml"/>
<xsl:template match="h:h1|h:h2"> <p> LOOK MA! <xsl:apply-templates select="@*|node()"/> NO BRAINS! </p> </xsl:template>
<xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
</xsl:transform>
I have four test documents that look something like this:
<?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"> <head id="test_head_attr"> <title>Sample title</title> </head> <body id="test_body_attr"> <h1>Sample H1</h1> <h2>Sample H2</h2> <p>Body text <br /> Other stuff. <br /></p> </body> </html>
One of the four has both the DOCTYPE declaration and an xmlns attribute, one has the DOCTYPE declaration but no xmlns attribute, one has no DOCTYPE declaration but an xmlns attribute, and one has neither a DOCTYPE declaration nor an xmlns attribute. I'd *like* to get a stylesheet that produced the same results on all four test documents, but I'd settle for getting it to work on the documents that set the xmlns attribute explicitly in the html element and the documents with the DOCTYPE declaration.
I've tried variants on this with the exclude-result-prefixes attribute of xsl:stylesheet and also tried messing with the xsl:namespace-alias element, but can't seem to this to produce the same output on both xsltproc and Saxon, and I keep getting invalid output with attributes like xmlns="" or xmlns:h="http://www.w3.org/1999/xhtml".
Any idea how to do this right?
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Trouble with namespaces a, James J. Ramsey | Thread | Re: [xsl] Trouble with namespaces a, David Carlisle |
Re: [xsl] xsl search engine, Robert Koberg | Date | Re: [xsl] node selection problem, Wendell Piez |
Month |