I am trying to convert XHTML using an XSLT stylesheet, but I can't even get a basic stylesheet to fit anything. I am sure that I am missing something simple.
Here is my original XHTML document (no big surprises):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="generator" content= "HTML Tidy for Windows (vers 25 March 2009), see www.w3.org" /> ... </body> </html>
Actual content doesn't matter much, as I will show below. By the way, I am sure that the document is well-formed, since it was created through tidy -asxml .
My more complex XPath expressions did not return any results, since the health test, I am trying to convert it very simply using the following stylesheet:
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" omit-xml-declaration="yes" indent="no"/> <xsl:template match="/"> <xsl:text>---[</xsl:text> <xsl:for-each select="html"> <xsl:text>Found HTML element.</xsl:text> </xsl:for-each> <xsl:text>]---</xsl:text> </xsl:template> </xsl:stylesheet>
The conversion is done through xsltproc --nonet stylesheet.xsl input.html , and the output is "--- [] ---" (that is, it did not find the html child). However, if I changed the for-each section to:
<xsl:for-each select="*"> <xsl:value-of select="name()"/> </xsl:for-each>
Then I get "--- [html] ---". And similarly, if I use for-each select="*/*" , I get "--- [headbody] ---", as you would expect.
Why can he find the child through * (with name() with the correct name), but he will not find it directly using the name of the element?