Next in thread → Next in month →

Re: [docbook] XPath expression for book title

From
Stephen Taylor <>
Date
2008-08-24T16:30:21+00:00
ID
Thread
Re: [docbook] XPath expression for book title
Tom

Blimey. I'd forgotten XSLT processors don't validate by default. Pages of whinges resolved, and I got my title. Validity was the issue.

The winning XPath:

<xsl:value-of select="/d:book/d:info/d:title"/>

as I'd opted to make the title a child of info. 

So now I'll remember to Keep It Valid. Tx

Stephen

2008/8/24 Thomas Schraitle <>

Hi Stephen,

On Sonntag, 24. August 2008, Stephen Taylor wrote:

> Looking for an XPath expression that will give me the title of my book.

>

> I want the title element of my book reproduced in the running headers.

> In the header.content template <http://pastebin.com/m424a9b30> in my

> customisation layer I've been trying variations of

>

> <xsl:value-of select="/bookinfo/title"></xsl:value-of>

> <xsl:apply-templates select="/bookinfo/title" />

>

> but get an empty result.

First, from what I've seen, I fear your DocBook5 document is not valid.

DocBook5 does not have any bookinfo elements anymore. It is replaced with

info. As a rule of thumb, always validate your document before applying

any transformations on it. :)

Second, as you have a DocBook5 document, you have to use the respective

namespace in your stylesheets too. Declare it in your root element, for

example:

 <xsl:stylesheet version="1.0"

    xmlns:d="http://docbook.org/ns/docbook"

    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

   ...

 </xsl:stylesheet>

After this modification, you have to use the declared prefix on all your

DocBook5 elements:

 <xsl:apply-templates select="d:info/d:title"/>

However, a title can occur not only inside a d:info element, it can occur

directly after d:book too. Probably it is better to extend the above

expression like this (if your current context is d:book):

 <xsl:apply-templates select="(d:info/d:title|d:title)[1]"/>

This selects only one of the possible titles, either in d:info or in

d:book. If you need only the string content of a title regardless of the

elements inside, replace xsl:apply-templates with xsl:value-of.

This is just a general explanation, maybe you have to play with the

customization a bit and use other modes. See also Bob's book for more

information at http://www.sagehill.net/docbookxsl/index.html

> The document is modular: a short master

> document<http://pastebin.com/m6e07225c>includes a series of article

> documents. Is that changing the reference of

> the document root?

I'm not sure what you mean by "changing the reference of the document

root".

> If so, then

>

> <xsl:value-of select="/artheader/title"></xsl:value-of>

>

> would yield my article titles in the headers. But that doesn't happen

> either.

Probably the same issue as above.

Hope that helps,

Tom

--

Thomas Schraitle

---------------------------------------------------------------------

To unsubscribe, e-mail: 

For additional commands, e-mail: 
Next in thread → Next in month →