Link to home
Start Free TrialLog in
Avatar of GedB
GedB

asked on

MSXML XSLT is ignoring elements without a namespace.

I'm uaing MSXML2 to parse some XSL and I'm having real problems with namespaces.

My XML document has some elements with a namespace and some without.

The problem is that the elements without a namespace are being ignored by the stylesheet.

<xsl:value-of select="element-name"/> gives nothing, even though the name is definately valid.

If I uses this

<xsl:value-of select="*[name()='element-name']"/> it works.

Anything with a namespace also works fine.

Any ideas whats going on?

This is some sample xml:

<?xml version="1.0" encoding="utf-8"?>

<rdf:RDF
xmlns="http://"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"


<channel rdf:about="http://www.blahblah.com">

<title>Title Title</title>
<description>
Test Text Text Test Text TextTest Text TextTest Text TextTest Text Text
Test Text Text Test Text TextTest Text TextTest Text TextTest Text Text
Test Text Text Test Text TextTest Text TextTest Text TextTest Text Text
Test Text Text Test Text TextTest Text TextTest Text TextTest Text Text
Test Text Text Test Text TextTest Text TextTest Text TextTest Text Text
</description>
<link>http://www.blahblah.com</link>
<dc:publisher>The Publisher</dc:publisher>
<dc:rights>? Copyright Stuff</dc:rights>
<dc:date>2001-09-10T10:31+00:00</dc:date>
<dc:creator>The creator</dc:creator>

<image rdf:resource="http://www.blahblah.com/images/piccy.gif" />

</channel>


</rdf:RDF>


and this is my xsl:

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
version="1.0">


<xsl:output method="html" version="4.0"/>

<xsl:template match="rdf:RDF">
<html>
<head>
<title>Name Space Problem</title>
</head>
<body>
<xsl:apply-templates select="*"/>
</body>
</html>
</xsl:template>

<xsl:template match="*[name()='channel']">

<h1><xsl:value-of select="title"/></h1>
<p><xsl:value-of select="description"/></p>
<font size="small" color="gray">
<center><xsl:value-of select="dc:creator"/></center>
<center><xsl:value-of select="dc:publisher"/></center>
<center><xsl:value-of select="dc:rights"/></center>
<center><xsl:value-of select="dc:date"/></center>

</font>

</xsl:template>

<xsl:template match="*">
<font size="large" color="red">Thats no good</font>
</xsl:template>


</xsl:stylesheet>


This is driving me round the bend, so any help would be appreciated.


ASKER CERTIFIED SOLUTION
Avatar of chabaud
chabaud

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GedB
GedB

ASKER

I knew the namespace was to blame, but the Microsoft documentation is rather weak in this area.  

The exclude-result-prefixes is a great tip, too.

Thannks.