xsl-list
[Top] [All Lists]

[xsl] Namespace getting carried over to output XML

2006-07-11 07:53:39
Hi,
    I tried to apply a xsl on a xhtml document and once it passes
through the xsl, I am getting the namespace carried over to my output
xhtml document in places unnecessary. Below is an example.

I have given the following line when I start my XSL

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform "
xmlns:xhtml="http://www.w3.org/1999/xhtml " xmlns="
http://www.w3.org/1999/xhtml"; xmlns:abc="abctest"
exclude-result-prefixes="abc">


I have a tag in my source xhtml which is like:

<a href="/contents/myfolder/abc.htm">Click here</a>

My xsl is supposed to change <a href> to my custom tag. Basically my
output should be

<abc:link linkend="/contents/myfolder/abc.htm">Click here</abc:link>

The "a" is replaced by "abc:link" and "href" is replaced by "linkend"

The problem is my output is coming this way
<abc:link xmlns:xhtml=" http://www.w3.org/1999/xhtml "
xmlns:abc="abctest" linkend="/contents/myfolder/abc.htm">Click
here</abc:link>

The namespace is getting carried over to the output in the place where
I am replacing the text. For reference, below is my full XSL

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"; xmlns:xhtml="
http://www.w3.org/1999/xhtml"; xmlns=" http://www.w3.org/1999/xhtml";
xmlns:abc="abctest" exclude-result-prefixes="abc">
<!--Copying through all the contents of the <html> and <head> tags-->
<xsl:output method="xml" version="1.0" indent="yes" doctype-system="
http://www.w3.org/TR/xhtml1/DTD/xhtml1-translational.dtd";
doctype-public="-//W3C/DTD XHTML 1.0 Transitional//EN"/>
<xsl:template match="/">
 <xsl:apply-templates/>
</xsl:template>

<!-- Normally, the transformed XML elements will match this template,
which just copies them into the output stream-->
<!-- THE REPLACEMENT PORTION-->
<xsl:template name="anchor">
 <xsl:choose>
  <xsl:when test="@href">
   <xsl:choose>
    <xsl:when test="contains(@href,':') ">
     <xsl:element name="pwc:ulink">
            <xsl:attribute name="url">
            <xsl:value-of select="@href"/>
             </xsl:attribute>
      <xsl:value-of select="."/>
     </xsl:element>
    </xsl:when>
    <xsl:otherwise>
     <xsl:element name="link">
         <xsl:attribute name="linkend">
          <xsl:value-of select="@href"/>
         </xsl:attribute>
      <xsl:value-of select="."/>
     </xsl:element>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:when>
  <xsl:otherwise>
   <xsl:apply-templates/>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>

<!--SEARCH FOR LINK AND REPLACE WITH ABC:LINK -->
<xsl:template match="@* | node() | processing-instruction()">
 <xsl:choose>
  <xsl:when test="name()='a'">
   <xsl:call-template name="anchor"/>
  </xsl:when>
  <xsl:otherwise>
   <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
   </xsl:copy>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>
</xsl:stylesheet>


Any help would be highly appreciated.

Thanks
Prashanth

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>