Subject: Re: [docbook-apps] customize <exmaple> to use the attribute of label as caption
This is certainly possible, but not as simple as it might be.
Without any customization, the label attribute in DocBook can be used to override just the number, not the entire "Example 3: Blah Blah". So you could set label="Listing 1", and the result would be "Example Listing 1: Blah Blah", which is probably not what you want.
Normally I would suggest using example with a role attribute to distinguish your two kinds of examples:
<example><title>A regular example</title>
<example role="listing"><title>A programlisting</title>
Then you would customize templates to select one or the other kind of example:
match="example[@role = 'listing']"
match="example[not(@role) or @role != 'listing']"
The problem is that in the DocBook stylesheets, the number and title can appear in more places than just the title on the example. For example, if you turn on a List of Examples in the Table of Contents, or if you cross reference to an example. This means there are several templates that would need customization to distinguish between the two kinds of example elements. You are also creating a separate numbering scheme, so those numbers have to be kept separate as well. Another complication is that the word "Example" is generated text, and so it is handled by the templates that handle localized text.
I might suggest a simpler approach if you don't want to get into all that. You could instead put a <lineannotation> element at the start of your programlisting, and customize a template to handle that.
<programlisting><lineannotation role="listingtitle">PHP Program Code</lineannotation># First line of code
With this approach, you don't get into the Example templates at all, so you can avoid all those complications. You can simply define a template that formats the title the way you want, including generating a count. Something like this:
<xsl:template match="lineannotation[@role = 'listingtitle']">
<xsl:number count="lineannotation[@role = 'listingtitle']" level="any"/>
Some caveats: If you want to cross reference to such programlisting elements, then you'll need to do more. If you translate your content, then you won't want to hardcode "Listing" in the stylesheet. And then, if you do syntax highlighting or automatic line numbering in your programlistings, all bets are off. 8^)