Re: [xsl] Transform xhtml to xhtml, convert one tag to another, while preserving rest of file

Subject: Re: [xsl] Transform xhtml to xhtml, convert one tag to another, while preserving rest of file
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 07 Feb 2005 15:29:01 -0500

At 03:21 PM 2/7/2005, you wrote:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="";>

<xsl:output method="xml" version="1.0" omit-xml-declaration="yes" />

<xsl:template match="reference">
<a href="{@page}"><xsl:value-of select="text()" /></a>
<!-- I've also tried <xsl:comment>test</xsl:comment> and <xsl:text>test</xsl:text> as the only contents of the template -->

<xsl:template match="node()|@*">
        <xsl:apply-templates select="node()|@*"/>


This should work. Your troubleshooting suggests the template matching "reference" is not getting matched.

You may have seen another thread go by, in which the OP learned that if an element name is in a namespace, even if without a prefix, it has to be prefixed to match:

<xsl:template match="n:reference">...

with xmlns:n declared to match the xmlns namespace declaration in your source.

Could this be the problem here?

I'm using Xalan (integrated with Apache Ant) for my transformations. Could this have _anything_ to do with it?

Yes, it's but not very likely. This is basic and the same version of Xalan is already doing it correctly thousands of times a day.

Or am I at fault?

No doubt, or your grade-school math teacher, who didn't teach you about XML namespaces. (We're shocked!)

I'd show the XHTML file that needs to get processed and the <reference> template, but their both quite big, and don't seem to have anything to do with it, since I don't get any warnings or errors.

The template isn't getting matched at all ... so the question is why. An incorrect namespace binding could well be the culprit.

Note that in:



<element xmlns="mynamespace">

... the two "child" elements do *not* have the same name, despite appearances.

To make matters worse, the *only* way in XSLT to match the child by name in the second example is with an explicit prefix:

match="n:child" xmlns:n="mynamespace"

... I hope that helps.


Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
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