Welcome to the wonderful world of namespaces.
Try adding to your xsl:stylesheet
xmlns:xhtml="http://www.w3.org/1999/xhtml"
And in your XPaths use the namespace like so:
count(//xhtml:img)
Does that fix it? If so, this is not a Sab bug.
The selector in your XPath (img) is in no namespace (sometimes known as the
null namespace). The target in your document is in the XHTML namespace.
When you remove the default xmnls declaration from your input document,
things work, because then your input is in the null namespace also.
Tidy is doing the right thing; see the XHTML spec. It is also *correct* for
count(//img) *not* to match <img xmlns="http://www.w3.org/1999/xhtml">.
(See http://www.w3.org/TR/xpath#node-tests).
I just noticed that libxslt gets this wrong, though. I don't have Sab on
this particular machine, so I can't test to see if it behaves properly (like
Saxon) or improperly like libxslt).
This is basically not a Sab question at all; on namespaces and all other XSL
issues see the XSL faq at http://www.dpawson.co.uk.
Steve
On Saturday 19 May 2001 02:08 pm, you wrote:
> I have the following Files:
>
> XHTML (test.xml):
> ============
> <?xml version="1.0" encoding="UTF-8"?>
> <html xmlns="http://www.w3.org/1999/xhtml">
> <img src="test.jpg"/>
> </html>
>
> XSL (test.xsl)
> ===========
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <!-- (C) Bernhard Zwischenbrugger, Datenkueche -->
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
> <xsl:output method="html" indent="no" encoding="ISO-8859-1"/>
>
> <xsl:template match="/">
> number of images:
> <xsl:value-of select="count(//img)"/>
> </xsl:template>
> </xsl:stylesheet>
>
> bash-2.03# sabcmd test.xsl test.xml
> number of images:
> 0
>
> -----------------------
> I thought the number of images is "1".
>
> If I replace
> <html xmlns="http://www.w3.org/1999/xhtml">
> with
> <html>
> there is no problem. (count=1)
>
> The xhtml File is generated by tidy and there is no option to
> generate an xhtml file without "xmlns".
>
> Is this a Bug?
> Is there a workaround?
>
> -----------------------------------------------------
> Bernhard Zwischenbrugger Datenk�che
> Tel.: +43/1/944 57 64 Redaktionssystem
> Mobil.: +43/699/1944 57 64 Web Content Management
> -----------------------------------------------------
> http://www.datenkueche.com