xslt count error

M

Miel Bronneberg

Hi,

When I transform the following xml document

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE minim SYSTEM "http://www.cs.vu.nl/~embronne/XML/minim/minim.dtd">
<minim xmlns="http://www.cs.vu.nl/~embronne/XML/minim"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.cs.vu.nl/~embronne/XML/minim
http://www.cs.vu.nl/~embronne/XML/minim/minim.xsd">
<lmnt>
<slmnt>1.one</slmnt>
</lmnt>
<lmnt>
<slmnt>2.one</slmnt>
</lmnt>
</minim>

using the following xslt stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Test database</title>
</head>
<body>
<h1>Minimal DataBase</h1>
<div>
Number of elements "lmnt":
<xsl:value-of select="count(minim/lmnt)"/>
</div>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="*">
</xsl:template>
</xsl:stylesheet>

it returns the following html document:

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test database</title>
</head>
<body>
<h1>Minimal DataBase</h1>
<div>
Number of elements "lmnt":
0</div>
</body>
</html>

Of course, this is the wrong number of elements. I can't figure this out.
What might help you figure it out, but puzzles me just as much, is that,
even though the xml document validates OK, both against the dtd and the
schema, the correct output is produced when I leave the doctype declaration
and the reference to the schema out of the xml document, like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<minim>
<lmnt>
<slmnt>1.one</slmnt>
</lmnt>
<lmnt>
<slmnt>2.one</slmnt>
</lmnt>
</minim>

What's going on here?

Thanks, regards, Miel.
 
P

Philippe Poulard

hi,

the result of your count() function returns the right answer : there are
no namespace-unbouded lmnt elements in your document; however, there are
2 lmnt elements bound to http://www.cs.vu.nl/~embronne/XML/minim

as you bound your elements to a namespace uri, you have to do so in the
stylesheet; however, this can be done *only* thanks to prefixes :

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mini="http://www.cs.vu.nl/~embronne/XML/minim"....
<xsl:value-of select="count(mini:minim/mini:lmnt)"/>
....

remember that unprefixed attributes are not in a namespace, so :
mini:minim/mini:lmnt/@foo
will match :
<lmnt foo="bar">


Miel said:
Hi,

When I transform the following xml document

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE minim SYSTEM "http://www.cs.vu.nl/~embronne/XML/minim/minim.dtd">
<minim xmlns="http://www.cs.vu.nl/~embronne/XML/minim"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.cs.vu.nl/~embronne/XML/minim
http://www.cs.vu.nl/~embronne/XML/minim/minim.xsd">
<lmnt>
<slmnt>1.one</slmnt>
</lmnt>
<lmnt>
<slmnt>2.one</slmnt>
</lmnt>
</minim>

using the following xslt stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Test database</title>
</head>
<body>
<h1>Minimal DataBase</h1>
<div>
Number of elements "lmnt":
<xsl:value-of select="count(minim/lmnt)"/>
</div>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="*">
</xsl:template>
</xsl:stylesheet>

it returns the following html document:

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test database</title>
</head>
<body>
<h1>Minimal DataBase</h1>
<div>
Number of elements "lmnt":
0</div>
</body>
</html>

Of course, this is the wrong number of elements. I can't figure this out.
What might help you figure it out, but puzzles me just as much, is that,
even though the xml document validates OK, both against the dtd and the
schema, the correct output is produced when I leave the doctype declaration
and the reference to the schema out of the xml document, like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<minim>
<lmnt>
<slmnt>1.one</slmnt>
</lmnt>
<lmnt>
<slmnt>2.one</slmnt>
</lmnt>
</minim>

What's going on here?

Thanks, regards, Miel.


--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
 
M

Miel Bronneberg

: hi,

: the result of your count() function returns the right answer : there are
: no namespace-unbouded lmnt elements in your document; however, there are
: 2 lmnt elements bound to http://www.cs.vu.nl/~embronne/XML/minim

: as you bound your elements to a namespace uri, you have to do so in the
: stylesheet; however, this can be done *only* thanks to prefixes :

Thanks, this was a very frustrating problem.

: remember that unprefixed attributes are not in a namespace, so :
: mini:minim/mini:lmnt/@foo
: will match :
: <lmnt foo="bar">

I'll try to remember.

Thanks again, regards, Miel.
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top