xslt count error

Discussion in 'XML' started by Miel Bronneberg, Oct 24, 2003.

  1. 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.
     
    Miel Bronneberg, Oct 24, 2003
    #1
    1. Advertising

  2. 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 |
    -----------------------
     
    Philippe Poulard, Oct 24, 2003
    #2
    1. Advertising

  3. Philippe Poulard <> 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.
     
    Miel Bronneberg, Oct 24, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcel Akkerman
    Replies:
    5
    Views:
    901
    Marcel Akkerman
    Feb 22, 2004
  2. M.Kamermans

    XSLT - maintaining iteration count

    M.Kamermans, Jan 29, 2005, in forum: XML
    Replies:
    6
    Views:
    8,304
    Dimitre Novatchev
    Jan 30, 2005
  3. John Wilkinson

    XSLT incrementing count

    John Wilkinson, Sep 5, 2005, in forum: XML
    Replies:
    2
    Views:
    1,532
    toudidel
    Sep 6, 2005
  4. Replies:
    4
    Views:
    31,816
  5. efelnavarro09
    Replies:
    2
    Views:
    957
    efelnavarro09
    Jan 26, 2011
Loading...

Share This Page