OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

docbook-apps message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: Re: [docbook-apps] Can't select link if 'linkend' contains text


Hi,

Am Freitag, 23. Dezember 2011, 22:34:28 schrieb Xmplar:
> I have in a document, d:link - for both links to other text in the
> document (e.g. link to a figure) as well as links to URLs.
> For both types of links I am using d:link.

Any special reason why you omit <xref/>s?

For cross references inside the document itself, I would prefer <xref/> over 
<link>. The <xref/> element resolves the reference into the title with 
additional information, whereas <link> does not. 

Depending on what you insert into <link>, you have to rework your text 
whenever a title changes. This is additional work which could be avoided by 
using <xref/>s.


> I would like the following code to
> select only those instances where the @linkend contains the string
> 'http' - and to then put angle brackets before and after those URLs. The
> if:test syntax under variable "content" is obviously wrong - what is the
> correct syntax for selecting linkends that are only URLs?
> Thanks
> 
> <xsl:template match="d:link" name="link">
> [...] 
> <xsl:variable name="content">
> <xsl:if test="contains(linkend,'http')">
                ^^^^^^^^^^^^^^^^
This expression has several issues:

1. If you write "linkend" it selects a child element instead of 
   the attribute. This test will always fail as DocBook never
   had a "linkend" element.
2. Using linkend attribute here is actually wrong. What you need 
   is @xlink:href.
   Use the linkend attribute only for internal cross-references
   (or better avoid it altogether and replace it with <xref/>
   as pointed out above).
3. I would recommend to replace the contains() function with
   starts-with() as URLs normally starts with a URL scheme like 
   http, https, ftp, ... 
   Using contains() in this context is a source for bugs which are
   hard to find. :)

Apart from the above code, you could radically simplify the code by using a 
different approach:

  <xsl:template match="d:link[starts-with(@xlink:href, 'http')]">
    <xsl:text>[</xsl:text>
    <xsl:apply-imports/>
    <xsl:text>]</xsl:text>
  </xsl:template>

All the complicated link creation is delegated to the original template (using 
xsl:apply-imports).



-- 
Gruß/Regards
  Thomas Schraitle



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]