Conal Tuohy <[EMAIL PROTECTED]> writes:

> Peter Hunsberger wrote:
> 
> > Conal Tuohy <[EMAIL PROTECTED]> wrote:
> > 
> > > Alfred Fuchs wrote:
> > > 
> > > > in my expamle I extract the title of a HTML page in this way: if
> > > > <title> exist and <title> not empty, use it as title. 
> > otherwise use
> > > > the first <h1> etc... this is logic, simply done in a xslt,
> > > but hoe to
> > > > do this in a single xpath-query?
> > > 
> > > string(/html/head/title[normalize-space()]|/html/body//h1[1])
> > 
> > Except that will get both when both exists, which I don't
> > think is what
> > he wanted...
> 
> He should only get the title if the title exists:
> 
> The first sub-expression 
> "/html/head/title[normalize-space()]" defines a nodeset 
> containing any non-whitespace title element.
> 
> The second expression "/html/body//h1[1]" selects a nodeset 
> containing the first heading 1.
> 
> The | operator merges the 2 nodesets.
> 
> The string() function returns the string value of the FIRST 
> NODE in the resulting nodeset.

Ahh, that would do the trick.  I believe in some old implementations
(Xerces/Xalan) I've run into that wasn't the case; I'm pretty sure I've
seen the union of the strings.

Might be a tad expensive, but most likely he can be more specific on the
path to the h1...

Reply via email to