tags:

views:

44

answers:

2

I'm trying to get title of simple html document to build sitemap. But always return empty value. I debug this and found out that document(content) returns document nodes. It looks like this.alt text But I could not access document(content)/html or something like this. Please help!

+2  A: 

Some more code would help, but in such situations the first one to blame is namespace. I can see that your nodes are in the XHTML namespace, but you do not use any namespace prefix in your XPath.

You have to declare namespace prefix in your stylesheet like this:

<xsl:stylesheet 
  version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:h="http://www.w3.org/1999/xhtml"
>

And then use this prefix in your XPath like this:

document(content)/h:html
calavera.info
What should I do to fix this?
Artic
Thanx a lot!!!!
Artic
+1  A: 

If your xml elements are in a namespace, even if it is the default namespace for the document, you must use namespace prefixes in any XPath expressions and template match rules. It is the namespace uri and not the prefix that matters. Note that attributes will not be in the default namespace, they only have a namespace if their name has a prefix.

Additionally, an XPath expression containing // is usually less efficient than one that does not.

<xsl:stylesheet version="1.0"
            xmlns:h="http://www.w3.org/1999/xhtml"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;


<!-- and elsewhere in your stylesheet -->
<xsl:value-of select="document(content)/h:html/h:head/h:title"/>
Lachlan Roche
How could I know what namespace to use?
Artic