[xsl] Node renaming problem

Subject: [xsl] Node renaming problem
From: Greg Faron <gfaron@xxxxxxxxxxxxxxxxxx>
Date: Wed, 09 Oct 2002 15:26:49 -0600

It's been over a year since I last worked with XSL and am having a difficult time remembering the simplest of things. In a current project, I want to add a prefix to a particular node tree such that



(The subnodes must carry the prefix because that is how the third-party browser plugin is configured to parse them.)

I wrote the following named template, but I think I did it the hard way. Plus my test for text-only nodes is incorrect.

<xsl:template name="str:prepend-ns">
<xsl:param name="tags" select="."/>
<xsl:param name="ns" select="'alt'"/>
<xsl:for-each select="$tags">
<!-- WRONG -->
<xsl:when test=".=text()">
<xsl:copy-of select=."/>
<xsl:variable name="tagName" select="concat($ns, ':', local-name(.))"/>
<xsl:element name="{$tagName}">
<xsl:call-template name="str:prepend-ns">
<xsl:with-param name="tags" select="child::node()"/>
<xsl:with-param name="ns" select="$ns"/>

This is the result using MSXSL4.0:
<m:math xmlns="">
  <m:apply xmlns="">
    <m:power xmlns="" />

1) How should I properly check to see if the current node is a text()?
2) How do I avoid the unnecessary xmlns="" attributes?
3) Am I overcomplicating everything?

Greg Faron Integre Technical Publishing Co.

XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list

Current Thread