<copy-of/> without resulting empty namespace ?
Posted: Thu Jan 19, 2006 7:15 pm
Hello,
Could someone explain the most efficient way for freeing <copy-of /> output elements from empty namespace attribute (<yyy xmlns=" " /> ?
Here is my source :
Here the result :
this is bad !
And here the XSLT :
Whatever I tried did not do it, so if someone has a clue I will be delighted
Thank you for reading !!
Could someone explain the most efficient way for freeing <copy-of /> output elements from empty namespace attribute (<yyy xmlns=" " /> ?
Here is my source :
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<site>
<chapitre>
<page>index</page>
<contenu>
<h3>Grand Titre (without namespace declaration)</h3>
<h2 xmlns="http://www.w3.org/1999/xhtml">Petit Titre (with xmlns="http://www.w3.org/1999/xhtml" namespace declaration in source)</h2>
</contenu>
<titre-chap>L'accueil du site</titre-chap>
</chapitre>
</site>
Code: Select all
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta http-equiv="Content-Language" content="fr" />
<title>L'accueil du site</title>
</head>
<body>
<h3 xmlns="">Grand Titre (without namespace declaration)</h3>
<h2>Petit Titre (with xmlns="http://www.w3.org/1999/xhtml" namespace declaration in source)</h2>
<ul>
<li><a href="http://xtest.com/index.htm">L'accueil du site</a></li>
</ul>
</body>
</html>
<h3 xmlns="">Grand Titre (without namespace declaration)</h3>
And here the XSLT :
Code: Select all
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" encoding="ISO-8859-1"></xsl:output>
<xsl:template name="for-loop">
<xsl:param name="i" select="1"/>
<xsl:param name="increment" select="1"/>
<xsl:param name="operator" select= " '=' "/>
<xsl:param name=" testValue" select="1"/>
<xsl:param name=" chapPage" select="1"/>
<xsl:variable name="testPassed">
<xsl:if test="$i <= $testValue">
<xsl:text>true</xsl:text>
</xsl:if>
</xsl:variable>
<xsl:if test="$testPassed = 'true' ">
<li xmlns="http://www.w3.org/1999/xhtml">
<a>
<xsl:attribute name="href" select=" concat('http://xtest.com/',//chapitre[$i]/page,'.htm') "></xsl:attribute>
<xsl:value-of select="//chapitre[$i]/titre-chap"/>
</a>
</li>
<xsl:call-template name="for-loop" xmlns="http://www.w3.org/1999/xhtml">
<xsl:with-param name="i" select="$i + $increment"/>
<xsl:with-param name="increment" select="$increment"/>
<xsl:with-param name="operator" select="$operator"/>
<xsl:with-param name="testValue" select="$testValue"></xsl:with-param>
<xsl:with-param name="chapPage" select="$chapPage"></xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates select="//contenu">
</xsl:apply-templates>
</xsl:template>
<xsl:template match="contenu">
<xsl:result-document href="{preceding-sibling::page}{'.htm'}" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/1999/xhtml" encoding="ISO-8859-1" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"></meta>
<meta http-equiv="Content-Language" content="fr"></meta>
<title><xsl:value-of select="following-sibling::titre-chap"/>
</title>
</head>
<body>
<xsl:copy-of select="node()" />
<ul>
<xsl:call-template name="for-loop">
<xsl:with-param name="i" select="1"/>
<xsl:with-param name="increment" select="1"/>
<xsl:with-param name="operator" select= " '<=' "/>
<xsl:with-param name=" testValue" select="count(//chapitre)"/>
<xsl:with-param name=" chapPage" select="count(ancestor::chapitre/preceding-sibling::*)"/>
</xsl:call-template>
</ul>
</body>
</html>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
Thank you for reading !!