![]() |
xslt count error
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. |
Re: xslt count error
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 Bronneberg wrote: > 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 | ----------------------- |
Re: xslt count error
Philippe Poulard <Philippe.Poulard@sophia.inria.fr> wrote:
: 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. |
| All times are GMT. The time now is 07:35 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.