[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]
Subject: Re: [docbook-apps] xsl & unix functions
----- Original Message -----
From: "Sam Steingold" <sds@gnu.org>
To: <docbook-apps@lists.oasis-open.org>
Sent: Tuesday, August 23, 2005 4:23 PM
Subject: [docbook-apps] xsl & unix functions
> I want
> <function role="unix">select</function>
> and
> <ulink role="unix" url="foo">bar</ulink>
> to be rendered with a link to the SUS page.
> here is what I came up with so far:
>
> <xsl:param name="unix.top"
> select="'http://www.opengroup.org/onlinepubs/007904975'"/>
> <xsl:template match="function[@role='unix']">
> <a class="{@role}"><xsl:attribute name="href">
> <xsl:value-of select="$unix.top"/>
> <xsl:text>/functions/</xsl:text>
> <xsl:value-of select="."/>
> <xsl:text>.html</xsl:text>
> </xsl:attribute>
> <xsl:apply-imports/>
> </a></xsl:template>
>
> <xsl:template match="ulink[@role='unix']">
> <a class="{@role}"><xsl:attribute name="href">
> <xsl:value-of select="$unix.top"/>
> <xsl:text>/</xsl:text>
> <xsl:value-of select="@url"/>
> </xsl:attribute>
> <xsl:apply-templates/>
> </a></xsl:template>
>
> 1. this works, but is not too good because this is HTML-specific.
> I want the element wrapped in <ulink> and then XSL re-applied.
> (to avoid infinite recursion, one would have to strip 'role="unix"'
> from the function element before re-application)
I don't understand this. What element do you want wrapped in ulink?
> 2. the exact same thing has to be done with variables, but
> <xsl:template match="function[@role='unix'] or varname[@role='unix']">
> does not work.
> what do I do?
The correct syntax in a match pattern is:
match="function[@role='unix'] | varname[@role='unix']">
> 3. <filename role="unix">sys/socket.h</filename>
> must be rendered with a link to
> "$unix.top"/basedefs/syssocket.h.html
> i.e., I need to strip "/" from "sys/socket.h"?
> also, I want it to be rendered as if it were written
> <filename><sys/socket.h></filename>
> (but I do not want to have to enter the </> inside <filename>)
If you want to strip all '/' characters from a string, you can use the
translate()
function and provide an empty third argument, which will translate such
characters to nothing:
translate($string, '/', '')
Adding the < and > should not be a problem for the template if you use
xsl:text.
> 4. suppose the URL cannot be inferred from the element contents easily,
> instead I have a table: a file "map" where odd lines are link content
> and even lines are URLs. I guess I need to read the file into a hash
> table and do somthing like this:
>
> (defparameter *map* (make-hash-table :test 'equal))
> ;; read map:
> (with-open-file (in "map")
> (loop for s1 = (read-line in nil nil) for s2 = (read-line in nil nil)
> while (and s1 s2)
> do (setf (gethash s1 *map*) s2)))
> ;; process <function role="clhs">FOO</function>
> (let ((destination (gethash <xsl:value-of select="."/> *map*)))
> (if destination
> <ulink url="destination">
> (apply-imports <function><xsl:value-of select="."/></function>)
> </ulink>
> (error "unknown function")))
>
> how do I express this in XSL?
This kind of thing is typically done with a recursive template. You might
look at how the 'generate.toc' parameter is handled using the
'find.path.params' template. It processes alternating tokens.
Bob Stayton
Sagehill Enterprises
DocBook Consulting
bobs@sagehill.net
>
> thanks!
>
> --
> Sam Steingold (http://www.podval.org/~sds) running w2k
> <http://www.iris.org.il> <http://www.savegushkatif.org>
> <http://www.dhimmi.com/> <http://www.honestreporting.com>
> If you try to fail, and succeed, which have you done?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: docbook-apps-unsubscribe@lists.oasis-open.org
> For additional commands, e-mail: docbook-apps-help@lists.oasis-open.org
>
>
>
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]