[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]
Subject: Re: [docbook-apps] xsl & unix functions
Sam Steingold wrote: > 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) There is one easy way how to implement this by misusing profiling stylesheets (this is possible because internally profiling stylesheets does two passes over input document). Just use profile-docbook.xsl instead of docbook.xsl and put something like this into customization layer: <xsl:template match="function[@role='unix']" mode="profile"> <ulink url="{$unix.top}/functions/{.}"> <xsl:copy-of select="."/> </ulink> </xsl:template> > 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? Use | instead of or. "or" cast is operand to boolean and is thus useles in match patterns. "|" in match patterns is like having two separate identical templates for each operand of "|". > 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>) Use same trick as above: <xsl:template match="filename[@role='unix']" mode="profile"> <ulink url="{$unix.top}/basedefs/{string-after(., '/')}"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:text><</xsl:text> <xsl:apply-templates select="node()"/> <xsl:text>></xsl:text> </xsl:copy> </ulink> </xsl:template> > 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? Create mapping in form of XML file. Something like: <!-- map.xml file --> <map> <data from="/foo/bar" to="fuu/baz"/> .... </map> To do mapping from "/foo/bar" you will just use simple XPath expression like: document("map.xml")/map/data[@from = '/foo/bar']/@to (Yep, sometimes XSLT+XPath way is really easier then DSSSL one. Sometimes not ;) You can define xsl:key to speedup lookups. HTH, Jirka -- ------------------------------------------------------------------ Jirka Kosek e-mail: jirka@kosek.cz http://www.kosek.cz ------------------------------------------------------------------ Profesionální školení a poradenství v oblasti technologií XML. Podívejte se na náš nově spuštěný web http://DocBook.cz Podrobný přehled školení http://xmlguru.cz/skoleni/ ------------------------------------------------------------------
S/MIME Cryptographic Signature
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]