开发者

<xsl:value-of select="document(content)//title"/> returns empty node

开发者 https://www.devze.com 2022-12-24 08:09 出处:网络
I\'m trying to get title of simple html document to build sitemap. Butalways return empty value. I debug this and found out that document(content) returns document nodes. It looks like this.alt text h

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 http://www.freeimagehosting.net/uploads/f7caf412dc.png But I coul开发者_开发技巧d not access document(content)/html or something like this. Please help!


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


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">


<!-- and elsewhere in your stylesheet -->
<xsl:value-of select="document(content)/h:html/h:head/h:title"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消