remove

M

Martin Honnen

N9 said:
I had a xslt that parse a XML document, output is HTML

But XSLT adding not valid code:
<ul class="level_1" xmlns="" xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance">

Show us the relevant XML input and the stylesheet, then we can help
improve the stylesheet.
 
N

N9

Hi

Here is my xslt.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:eek:utput omit-xml-declaration="yes" encoding="utf-8"
method="html" indent="no"/>

<xsl:variable name="firstMenuItemClass">first </xsl:variable>
<xsl:variable name="lastMenuItemClass">last </xsl:variable>
<xsl:variable name="selectedMenuItemClass">selected </xsl:variable>
<xsl:variable name="expandedMenuItemClass">expanded </xsl:variable>
<xsl:variable name="hasChildrenMenuItemClass">hasChildren </
xsl:variable>



<xsl:variable name="FilenamePrefix">
<xsl:value-of select="Navigation/@FilenamePrefix"/>
</xsl:variable>
<xsl:variable name="FileExtension">
<xsl:value-of select="Navigation/@FileExtension"/>
</xsl:variable>
<xsl:variable name="SelectedPageId">
<xsl:value-of select="Navigation/@PageId"/>
</xsl:variable>
<xsl:template match="Module" xml:space="default">

<xsl:choose>
<xsl:when test="Name='Sitemap'">
<div id="sitemap"><xsl:apply-templates select="Layout" /></div>
</xsl:when>
<xsl:eek:therwise>
<xsl:copy-of select="Layout"/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

<xsl:template match="Module">
<xsl:apply-templates select="Layout/Row" />
</xsl:template>
<xsl:template match="Layout/Row">
<xsl:apply-templates select="Cell[@Id='2']"/>
</xsl:template>
<xsl:template match="Cell">
<xsl:copy-of select="ContentArea/node()"/>
</xsl:template>
<xsl:template match="ContentArea"><xsl:copy-of select="node()"/></
xsl:template>
<xsl:template match="Navigation" xml:space="default">
<xsl:if test="NavigationElement[@ShowInNavigation='true']">
<ul>
<xsl:attribute name="class"><xsl:text/>level_<xsl:value-of
select="number(NavigationElement/@Level)+1" /></xsl:attribute>

<xsl:apply-templates
select="NavigationElement[@ShowInNavigation='true']"/>
</ul>
</xsl:if>
</xsl:template>
<xsl:template match="NavigationElement[@ShowInNavigation='true']"
xml:space="default">
<xsl:variable name="itemClass">
<xsl:if test="position() = 1">
<xsl:value-of select="$firstMenuItemClass" disable-output-
escaping="yes"/>
</xsl:if>
<xsl:if test="position() = last()">
<xsl:value-of select="$lastMenuItemClass" disable-output-
escaping="yes"/>
</xsl:if>
<xsl:if test="@Selected='true'">
<xsl:value-of select="$selectedMenuItemClass" disable-output-
escaping="yes"/>
</xsl:if>
<xsl:if test="@ChildSelected='true'">
<xsl:value-of select="$expandedMenuItemClass" disable-output-
escaping="yes"/>
</xsl:if>
<xsl:if test="@NumberOfChildren &gt; '0'">
<xsl:value-of select="$hasChildrenMenuItemClass" disable-
output-escaping="yes"/>
</xsl:if>
</xsl:variable>

<xsl:choose>

<xsl:when test="@PageId=339"><li class="fagfolk">Specielt for
fagfolk</li></xsl:when>

<xsl:when test="@PageId=540"><li class="fagfolk">Specielt for
fagfolk</li></xsl:when>

<xsl:when test="@PageId=892"><li class="fagfolk">Specielt for
fagfolk</li></xsl:when>

<xsl:when test="@PageId=893"><li class="fagfolk">Specielt for
fagfolk</li></xsl:when>
</xsl:choose>

<li>
<xsl:if test="not($itemClass='')">
<xsl:attribute name="class">
<xsl:copy-of select="normalize-space($itemClass)"/>
</xsl:attribute>
</xsl:if>
<a>
<xsl:if test="not($itemClass='')">
<xsl:attribute name="class">
<xsl:copy-of select="normalize-space($itemClass)"/>
</xsl:attribute>
</xsl:if>
<xsl:attribute name="href" xml:space="default">
<xsl:choose>
<xsl:when test="LongUrl != ''">/<xsl:value-of
select="LongUrl" disable-output-escaping="yes"/> said:
<xsl:value-of select="@PageId"/><xsl:value-of select="$FileExtension"/
</xsl:eek:therwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="NavigationTitle" disable-output-
escaping="yes"/>
</a>
<xsl:if test="NavigationElement[@ShowInNavigation='true']">
<ul>
<xsl:attribute name="class"><xsl:text/>level_<xsl:copy-of
select="number(NavigationElement/@Level)+1"/></xsl:attribute>

<xsl:apply-templates
select="NavigationElement[@ShowInNavigation='true']"/>
</ul>
</xsl:if>
</li>
</xsl:template>
<xsl:template match="*" />
</xsl:stylesheet>
 
J

Joseph J. Kesselman

But XSLT adding not valid code:
<ul class="level_1" xmlns="" xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance">
to remove that default).

If the problem is that you're trying to validate against a DTD which
doesn't allow those namespace declarations... well, DTDs are really not
fully compatable with namespaced documents, for just this sort of
reason. You can modify the DTD to allow namespace declarations to appear
anywhere, but since prefixes may change you can't really write a DTD
which will completely cover the possibilities.

Switching to schemas will solve that problem.

Meanwhile. you may be able to reduce the namespace declarations by
avoiding situations such as this one where the default namespace and/or
other prefixes are being redefined in the middle of the document. (The
reason it generated the xmlns= is that you were in a default namespace
context and then tried to output a non-namespaced <ul> element.) It's
also possible to tell XSLT not to output namespaces which aren't being
used, which may help if the xsi: is being copied when you didn't intend
it to be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top