[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

MSXML XSLT is ignoring elements without a namespace.

Posted on 2001-09-14
2
Medium Priority
?
395 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to count occurrences of each item in an array.

649 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