?
Solved

MSXML XSLT is ignoring elements without a namespace.

Posted on 2001-09-14
2
Medium Priority
?
390 Views
Last Modified: 2013-11-19
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.


0
Comment
Question by:GedB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
chabaud earned 800 total points
ID: 6483351
You really have a namespace problem.

It comes from the default namespace declared in your XML file. It's not the same as the XSL file one.

With no modification of the Xml file, the solution could be to append a foo namespace in XSL:

<xsl:stylesheet
     xmlns:foo="http://"
     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/"
     exclude-result-prefixes="rdf dc foo"
     version="1.0">

The exclude-result-prefixes attribute remove these namespace from resulting Html.

Then templates should use the foo namespace:

<xsl:template match="foo:channel">

<h1><xsl:value-of select="foo:title"/></h1>
<p><xsl:value-of select="foo:description"/></p>

0
 
LVL 1

Author Comment

by:GedB
ID: 6486069
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.
0

Featured Post

Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question