;; This is one of the files in Norm Walsh's Docbook XSL stylesheet set, ;; converted to Lx notation using command ;; "java uk.me.nxg.lx.helpers.LxWriter --mode=xslt common.xsl". ;; The subsequent tidying up consisted of adding the (dtd ...) element below, ;; making the corresponding changes "(when test: ...)" -> "(when ...)", ;; and tidying up some newlines. (lx:let ((namespace ((#f "http://www.w3.org/1999/XSL/Transform") ("doc" "http://nwalsh.com/xsl/documentation/1.0"))) (dtd ((when (test #t)) (param (name #t)) (variable (name #t))))) (stylesheet exclude-result-prefixes: doc version: 1.0 (lx:namespace ((#f "")) (doc:reference (referenceinfo (releaseinfo role: meta "$Id: common.lx,v 1.2 2004/05/12 21:56:00 norman Exp $") (author (surname Walsh) (firstname Norman)) (copyright (year 1999) (year 2000) (holder "Norman Walsh"))) (title "Common Template Reference") (partintro (section (title Introduction) (para "This is technical reference documentation for the DocBook XSL Stylesheets; it documents (some of) the parameters, templates, and other elements of the stylesheets.") (para "This is not intended to be" (quote user) "documentation. It is provided for developers writing customization layers for the stylesheets, and for anyone who's interested in" (quote "how it works") .) (para "Although I am trying to be thorough, this documentation is known to be incomplete. Don't forget to read the source, too :-)"))))) (preserve-space elements: *) (strip-space elements: " abstract affiliation anchor answer appendix area areaset areaspec artheader article audiodata audioobject author authorblurb authorgroup beginpage bibliodiv biblioentry bibliography biblioset blockquote book bookbiblio bookinfo callout calloutlist caption caution chapter citerefentry cmdsynopsis co collab colophon colspec confgroup copyright dedication docinfo editor entry entrytbl epigraph equation example figure footnote footnoteref formalpara funcprototype funcsynopsis glossary glossdef glossdiv glossentry glosslist graphicco group highlights imagedata imageobject imageobjectco important index indexdiv indexentry indexterm informalequation informalexample informalfigure informaltable inlineequation inlinemediaobject itemizedlist itermset keycombo keywordset legalnotice listitem lot mediaobject mediaobjectco menuchoice msg msgentry msgexplan msginfo msgmain msgrel msgset msgsub msgtext note objectinfo orderedlist othercredit part partintro preface printhistory procedure programlistingco publisher qandadiv qandaentry qandaset question refentry reference refmeta refnamediv refsect1 refsect1info refsect2 refsect2info refsect3 refsect3info refsynopsisdiv refsynopsisdivinfo revhistory revision row sbr screenco screenshot sect1 sect1info sect2 sect2info sect3 sect3info sect4 sect4info sect5 sect5info section sectioninfo seglistitem segmentedlist seriesinfo set setindex setinfo shortcut sidebar simplelist simplesect spanspec step subject subjectset substeps synopfragment table tbody textobject tfoot tgroup thead tip toc tocchap toclevel1 toclevel2 toclevel3 toclevel4 toclevel5 tocpart varargs variablelist varlistentry videodata videoobject void warning subjectset classsynopsis constructorsynopsis destructorsynopsis fieldsynopsis methodparam methodsynopsis ooclass ooexception oointerface simplemsgentry ") (lx:namespace ((#f "")) (doc:template name: is.component (refpurpose "Tests if a given node is a component-level element") (refdescription (para "This template returns '1' if the specified node is a component (Chapter, Appendix, etc.), and '0' otherwise.")) (refparameter (variablelist (varlistentry (term node) (listitem (para "The node which is to be tested."))))) (refreturn (para "This template returns '1' if the specified node is a component (Chapter, Appendix, etc.), and '0' otherwise.")))) (template name: is.component (param node select: .) (choose (when "local-name($node) = 'appendix' or local-name($node) = 'article' or local-name($node) = 'chapter' or local-name($node) = 'preface' or local-name($node) = 'bibliography' or local-name($node) = 'glossary' or local-name($node) = 'index'" 1) (otherwise 0))) (lx:namespace ((#f "")) (doc:template name: is.section (refpurpose "Tests if a given node is a section-level element") (refdescription (para "This template returns '1' if the specified node is a section\n(Section, Sect1, Sect2, etc.), and '0' otherwise.")) (refparameter (variablelist (varlistentry (term node) (listitem (para "The node which is to be tested."))))) (refreturn (para "This template returns '1' if the specified node is a section (Section, Sect1, Sect2, etc.), and '0' otherwise.")))) (template name: is.section (param node select: .) (choose (when "local-name($node) = 'section' or local-name($node) = 'sect1' or local-name($node) = 'sect2' or local-name($node) = 'sect3' or local-name($node) = 'sect4' or local-name($node) = 'sect5' or local-name($node) = 'refsect1' or local-name($node) = 'refsect2' or local-name($node) = 'refsect3' or local-name($node) = 'simplesect'" 1) (otherwise 0))) (lx:namespace ((#f "")) (doc:template name: section.level (refpurpose "Returns the hierarchical level of a section.") (refdescription (para "This template calculates the hierarchical level of a section. The element" (sgmltag sect1) "is at level 1," (sgmltag sect2) "is at level 2, etc.") (para "Recursive sections are calculated down to the fifth level.")) (refparameter (variablelist (varlistentry (term node) (listitem (para "The section node for which the level should be calculated. Defaults to the context node."))))) (refreturn (para "The section level," (quote 1) , (quote 2) ", etc.")))) (template name: section.level (param node select: .) (choose (when "name($node)='sect1'" 1) (when "name($node)='sect2'" 2) (when "name($node)='sect3'" 3) (when "name($node)='sect4'" 4) (when "name($node)='sect5'" 5) (when "name($node)='section'" (choose (when $node/../../../../../../section 6) (when $node/../../../../../section 5) (when $node/../../../../section 4) (when $node/../../../section 3) (when $node/../../section 2) (otherwise 1))) (when "name($node)='refsect1' or name($node)='refsect2' or name($node)='refsect3' or name($node)='refsection' or name($node)='refsynopsisdiv'" (call-template name: refentry.section.level (with-param name: node select: $node))) (when "name($node)='simplesect'" (choose (when $node/../../sect1 2) (when $node/../../sect2 3) (when $node/../../sect3 4) (when $node/../../sect4 5) (when $node/../../sect5 5) (when $node/../../section (choose (when $node/../../../../../section 5) (when $node/../../../../section 4) (when $node/../../../section 3) (otherwise 2))) (otherwise 1))) (otherwise 1))) (lx:namespace ((#f "")) (doc:template name: qanda.section.level (refpurpose "Returns the hierarchical level of a QandASet.") (refdescription (para "This template calculates the hierarchical level of a QandASet.")) (refreturn (para "The level," (quote 1) , (quote 2) ", etc.")))) (template name: qanda.section.level (variable section select: "(ancestor::section |ancestor::simplesect |ancestor::sect5 |ancestor::sect4 |ancestor::sect3 |ancestor::sect2 |ancestor::sect1 |ancestor::refsect3 |ancestor::refsect2 |ancestor::refsect1)[last()]") (choose (when "count($section) = '0'" 1) (otherwise (variable slevel (call-template name: section.level (with-param name: node select: $section))) (value-of select: "$slevel + 1")))) (template name: refentry.section.level (param node select: .) (variable RElevel (call-template name: refentry.level (with-param name: node select: "$node/ancestor::refentry[1]"))) (variable levelinRE (choose (when "name($node)='refsynopsisdiv'" 1) (when "name($node)='refsect1'" 1) (when "name($node)='refsect2'" 2) (when "name($node)='refsect3'" 3) (when "name($node)='refsection'" (choose (when $node/../../../../../refsection 5) (when $node/../../../../refsection 4) (when $node/../../../refsection 3) (when $node/../../refsection 2) (otherwise 1))))) (value-of select: "$levelinRE + $RElevel")) (template name: refentry.level (param node select: .) (variable container select: "($node/ancestor::section | $node/ancestor::sect1 | $node/ancestor::sect2 | $node/ancestor::sect3 | $node/ancestor::sect4 | $node/ancestor::sect5)[last()]") (choose (when $container (variable slevel (call-template name: section.level (with-param name: node select: $container))) (value-of select: "$slevel + 1")) (otherwise 1))) (template name: qandadiv.section.level (variable section.level (call-template name: qanda.section.level)) (variable anc.divs select: "ancestor::qandadiv") (value-of select: "count($anc.divs) + number($section.level)")) (template name: question.answer.label (variable deflabel (choose (when "ancestor-or-self::*[@defaultlabel]" (value-of select: "(ancestor-or-self::*[@defaultlabel])[last()] /@defaultlabel")) (otherwise (value-of select: $qanda.defaultlabel)))) (variable label select: @label) (choose (when "$deflabel = 'qanda'" (call-template name: gentext (with-param name: key (choose (when "local-name(.) = 'question'" question) (when "local-name(.) = 'answer'" answer) (when "local-name(.) = 'qandadiv'" qandadiv) (otherwise qandaset))))) (when "$deflabel = 'label'" (value-of select: $label)) (when "$deflabel = 'number' and local-name(.) = 'question'" (apply-templates select: "ancestor::qandaset[1]" mode: number) (choose (when "ancestor::qandadiv" (apply-templates select: "ancestor::qandadiv[1]" mode: number) (apply-templates select: "ancestor::qandaentry" mode: number)) (otherwise (apply-templates select: "ancestor::qandaentry" mode: number)))) (otherwise))) (template match: qandaset mode: number) (template match: qandadiv mode: number (number level: multiple from: qandaset format: 1.)) (template match: qandaentry mode: number (choose (when "ancestor::qandadiv" (number level: single from: qandadiv format: 1.)) (otherwise (number level: single from: qandaset format: 1.)))) (template name: object.id (param object select: .) (choose (when $object/@id (value-of select: $object/@id)) (otherwise (value-of select: "generate-id($object)")))) (template name: person.name (param node select: .) (variable style (choose (when $node/@role (value-of select: $node/@role)) (otherwise (call-template name: gentext.template (with-param name: context select: 'styles') (with-param name: name select: 'person-name'))))) (choose (when $node/personname (call-template name: person.name (with-param name: node select: $node/personname))) (when "name($node)='corpauthor'" (apply-templates select: $node)) (otherwise (choose (when "$style = 'family-given'" (call-template name: person.name.family-given (with-param name: node select: $node))) (when "$style = 'last-first'" (call-template name: person.name.last-first (with-param name: node select: $node))) (otherwise (call-template name: person.name.first-last (with-param name: node select: $node))))))) (template name: person.name.family-given (param node select: .) (apply-templates select: "$node//surname[1]") (if test: "$node//surname and $node//firstname" (text)) (apply-templates select: "$node//firstname[1]") (text "[FAMILY Given]")) (template name: person.name.last-first (param node select: .) (apply-templates select: "$node//surname[1]") (if test: "$node//surname and $node//firstname" (text ,)) (apply-templates select: "$node//firstname[1]")) (template name: person.name.first-last (param node select: .) (if test: $node//honorific (apply-templates select: "$node//honorific[1]") (value-of select: $punct.honorific)) (if test: $node//firstname (if test: $node//honorific (text)) (apply-templates select: "$node//firstname[1]")) (if test: "$node//othername and $author.othername.in.middle != 0" (if test: "$node//honorific or $node//firstname" (text)) (apply-templates select: "$node//othername[1]")) (if test: $node//surname (if test: "$node//honorific or $node//firstname or ($node//othername and $author.othername.in.middle != 0)" (text)) (apply-templates select: "$node//surname[1]")) (if test: $node//lineage (text ,) (apply-templates select: "$node//lineage[1]"))) (template name: person.name.list (param person.list select: "author|corpauthor|othercredit|editor") (param person.count select: "count($person.list)") (param count select: 1) (choose (when "$count > $person.count") (otherwise (call-template name: person.name (with-param name: node select: "$person.list[position()=$count]")) (choose (when "$person.count = 2 and $count = 1" (call-template name: gentext.template (with-param name: context select: 'authorgroup') (with-param name: name select: 'sep2'))) (when "$person.count > 2 and $count+1 = $person.count" (call-template name: gentext.template (with-param name: context select: 'authorgroup') (with-param name: name select: 'seplast'))) (when "$count < $person.count" (call-template name: gentext.template (with-param name: context select: 'authorgroup') (with-param name: name select: 'sep')))) (call-template name: person.name.list (with-param name: person.list select: $person.list) (with-param name: person.count select: $person.count) (with-param name: count select: $count+1))))) (variable arg.choice.opt.open.str "[") (variable arg.choice.opt.close.str "]") (variable arg.choice.req.open.str "{") (variable arg.choice.req.close.str "}") (variable arg.choice.plain.open.str (text)) (variable arg.choice.plain.close.str (text)) (variable arg.choice.def.open.str "[") (variable arg.choice.def.close.str "]") (variable arg.rep.repeat.str ...) (variable arg.rep.norepeat.str) (variable arg.rep.def.str) (variable arg.or.sep "|") (variable cmdsynopsis.hanging.indent 4pi) (template name: filename-basename (param filename) (param recurse select: "false()") (choose (when "substring-after($filename, '/') != ''" (call-template name: filename-basename (with-param name: filename select: "substring-after($filename, '/')") (with-param name: recurse select: "true()"))) (otherwise (value-of select: $filename)))) (template name: filename-extension (param filename) (param recurse select: "false()") (variable basefn (choose (when $recurse (value-of select: $filename)) (otherwise (call-template name: filename-basename (with-param name: filename select: $filename))))) (choose (when "substring-after($basefn, '.') != ''" (call-template name: filename-extension (with-param name: filename select: "substring-after($basefn, '.')") (with-param name: recurse select: "true()"))) (when $recurse (value-of select: $basefn)) (otherwise))) (lx:namespace ((#f "")) (doc:template name: select.mediaobject (refpurpose "Selects and processes an appropriate media object from a list") (refdescription (para "This template takes a list of media objects (usually the children of a mediaobject or inlinemediaobject) and processes the \"right\" object.") (para "This template relies on a template named \"select.mediaobject.index\" to determine which object in the list is appropriate.") (para "If no acceptable object is located, nothing happens.")) (refparameter (variablelist (varlistentry (term olist) (listitem (para "The node list of potential objects to examine."))))) (refreturn (para Calls < "apply-templates" > "on the selected object.")))) (template name: select.mediaobject (param olist select: "imageobject|imageobjectco |videoobject|audioobject|textobject") (variable mediaobject.index (call-template name: select.mediaobject.index (with-param name: olist select: $olist) (with-param name: count select: 1))) (if test: "$mediaobject.index != ''" (apply-templates select: "$olist[position() = $mediaobject.index]"))) (lx:namespace ((#f "")) (doc:template name: select.mediaobject.index (refpurpose "Selects the position of the appropriate media object from a list") (refdescription (para "This template takes a list of media objects (usually the children of a mediaobject or inlinemediaobject) and determines the \"right\" object. It returns the position of that object to be used by the calling template.") (para "If the parameter" (parameter use.role.for.mediaobject) "is nonzero, then it first checks for an object with a role attribute of the appropriate value. It takes the first of those. Otherwise, it takes the first acceptable object through a recursive pass through the list.") (para "This template relies on a template named \"is.acceptable.mediaobject\" to determine if a given object is an acceptable graphic. The semantics of media objects is that the first acceptable graphic should be used.") (para "If no acceptable object is located, no index is returned.")) (refparameter (variablelist (varlistentry (term olist) (listitem (para "The node list of potential objects to examine."))) (varlistentry (term count) (listitem (para "The position in the list currently being considered by the recursive process."))))) (refreturn (para "Returns the position in the original list of the selected object.")))) (template name: select.mediaobject.index (param olist select: "imageobject|imageobjectco |videoobject|audioobject|textobject") (param count 1) (choose (when "$use.role.for.mediaobject != 0 and $preferred.mediaobject.role != '' and $olist[@role = $preferred.mediaobject.role]" (for-each select: $olist (if test: "@role = $preferred.mediaobject.role and not(preceding-sibling::*[@role = $preferred.mediaobject.role])" (value-of select: "position()")))) (when "$use.role.for.mediaobject != 0 and $olist[@role = $stylesheet.result.type]" (for-each select: $olist (if test: "@role = $stylesheet.result.type and not(preceding-sibling::*[@role = $stylesheet.result.type])" (value-of select: "position()")))) (when "$use.role.for.mediaobject != 0 and $stylesheet.result.type = 'xhtml' and $olist[@role = 'html']" (for-each select: $olist (if test: "@role = 'html' and not(preceding-sibling::*[@role = 'html'])" (value-of select: "position()")))) (otherwise (if test: "$count <= count($olist)" (variable object select: "$olist[position()=$count]") (variable useobject (choose (when "name($object)='textobject' and $object/phrase and $object/@role='tex' and $stylesheet.result.type = 'fo' and $tex.math.in.alt != ''" (text 1)) (when "name($object)='textobject' and $object/phrase" (text 0)) (when "name($object)='textobject' and $object/ancestor::equation " (text 0)) (when "name($object)='textobject' and $object[not(@role) or @role!='tex']" (text 1)) (when "$object/ancestor::equation and $object/ancestor::equation/alt[@role='tex'] and $stylesheet.result.type = 'fo' and $tex.math.in.alt != ''" (text 0)) (when "$count = 1 and count($olist) = 1" (text 1)) (otherwise (choose (when "local-name($object) = 'imageobjectco'" (call-template name: is.acceptable.mediaobject (with-param name: object select: $object/imageobject))) (otherwise (call-template name: is.acceptable.mediaobject (with-param name: object select: $object))))))) (choose (when $useobject='1' (value-of select: $count)) (otherwise (call-template name: select.mediaobject.index (with-param name: olist select: $olist) (with-param name: count select: "$count + 1")))))))) (lx:namespace ((#f "")) (doc:template name: is.acceptable.mediaobject (refpurpose "Returns '1' if the specified media object is recognized.") (refdescription (para "This template examines a media object and returns '1' if the object is recognized as a graphic.")) (refparameter (variablelist (varlistentry (term object) (listitem (para "The media object to consider."))))) (refreturn (para "0 or 1")))) (template name: is.acceptable.mediaobject (param object) (variable filename (call-template name: mediaobject.filename (with-param name: object select: $object))) (variable ext (call-template name: filename-extension (with-param name: filename select: $filename))) (variable data select: "$object/videodata |$object/imagedata |$object/audiodata") (variable format select: $data/@format) (variable graphic.format (if test: $format (call-template name: is.graphic.format (with-param name: format select: $format)))) (variable graphic.ext (if test: $ext (call-template name: is.graphic.extension (with-param name: ext select: $ext)))) (choose (when "$use.svg = 0 and $format = 'SVG'" 0) (lx:namespace (("svg" "http://www.w3.org/2000/svg")) (when "$use.svg != 0 and $object/svg:*" 1)) (when "$graphic.format = '1'" 1) (when "$graphic.ext = '1'" 1) (otherwise 0))) (template name: mediaobject.filename (param object) (variable data select: "$object/videodata |$object/imagedata |$object/audiodata |$object") (variable filename (choose (when "$data[@fileref]" (value-of select: $data/@fileref)) (when "$data[@entityref]" (value-of select: "unparsed-entity-uri($data/@entityref)")) (otherwise))) (variable real.ext (call-template name: filename-extension (with-param name: filename select: $filename))) (variable ext (choose (when "$real.ext != ''" (value-of select: $real.ext)) (otherwise (value-of select: $graphic.default.extension)))) (variable graphic.ext (call-template name: is.graphic.extension (with-param name: ext select: $ext))) (choose (when "$real.ext = ''" (choose (when "$ext != ''" (value-of select: $filename) (text .) (value-of select: $ext)) (otherwise (value-of select: $filename)))) (when "not($graphic.ext)" (choose (when "$graphic.default.extension != ''" (value-of select: $filename) (text .) (value-of select: $graphic.default.extension)) (otherwise (value-of select: $filename)))) (otherwise (value-of select: $filename)))) (lx:namespace ((#f "")) (doc:template name: check.id.unique (refpurpose "Warn users about references to non-unique ID" s) (refdescription (para "If passed an ID in" (varname linkend) , (function check.id.unique) "prints a warning message to the user if either the ID does not exist or the ID is not unique.")))) (template name: check.id.unique (param linkend) (if test: "$linkend != ''" (variable targets select: "key('id',$linkend)") (variable target select: "$targets[1]") (if test: "count($targets)=0" (message (text "Error: no ID for constraint linkend:") (value-of select: $linkend) (text .))) (if test: "count($targets)>1" (message (text "Warning: multiple \"IDs\" for constraint linkend:") (value-of select: $linkend) (text .))))) (lx:namespace ((#f "")) (doc:template name: check.idref.targets (refpurpose "Warn users about incorrectly typed references") (refdescription (para "If passed an ID in" (varname linkend) , (function check.idref.targets) "makes sure that the element pointed to by the link is one of the elements listed in" (varname element-list) "and warns the user otherwise.")))) (template name: check.idref.targets (param linkend) (param element-list) (if test: "$linkend != ''" (variable targets select: "key('id',$linkend)") (variable target select: "$targets[1]") (if test: "count($target) > 0" (if test: "not(contains(concat(' ', $element-list, ' '), name($target)))" (message (text "Error: linkend (") (value-of select: $linkend) (text ") points to \"") (value-of select: "name($target)") (text "\" not (one of):") (value-of select: $element-list)))))) (param procedure.step.numeration.formats select: '1aiAI') (template name: procedure.step.numeration (param context select: .) (variable format.length select: "string-length($procedure.step.numeration.formats)") (choose (when "local-name($context) = 'substeps'" (variable ssdepth select: "count($context/ancestor::substeps)") (variable sstype select: "($ssdepth mod $format.length)+2") (choose (when "$sstype > $format.length" (value-of select: "substring($procedure.step.numeration.formats,1,1)")) (otherwise (value-of select: "substring($procedure.step.numeration.formats,$sstype,1)")))) (when "local-name($context) = 'step'" (variable sdepth select: "count($context/ancestor::substeps)") (variable stype select: "($sdepth mod $format.length)+1") (value-of select: "substring($procedure.step.numeration.formats,$stype,1)")) (otherwise (message (text "Unexpected context in procedure.step.numeration:") (value-of select: "local-name($context)"))))) (template match: step mode: number (param rest select: '') (param recursive select: 1) (variable format (call-template name: procedure.step.numeration)) (variable num (number count: step format: "{$format}")) (choose (when "$recursive != 0 and ancestor::step" (apply-templates select: "ancestor::step[1]" mode: number (with-param name: rest select: "concat('.', $num, $rest)"))) (otherwise (value-of select: "concat($num, $rest)")))) (template name: orderedlist-starting-number (param list select: .) (choose (when "not($list/@continuation = 'continues')" 1) (otherwise (variable prevlist select: "$list/preceding::orderedlist[1]") (choose (when "count($prevlist) = 0" 2) (otherwise (variable prevlength select: "count($prevlist/listitem)") (variable prevstart (call-template name: orderedlist-starting-number (with-param name: list select: $prevlist))) (value-of select: "$prevstart + $prevlength")))))) (template name: orderedlist-item-number (param node select: .) (choose (when $node/@override (value-of select: $node/@override)) (when "$node/preceding-sibling::listitem" (variable pnum (call-template name: orderedlist-item-number (with-param name: node select: "$node/preceding-sibling::listitem[1]"))) (value-of select: "$pnum + 1")) (otherwise (call-template name: orderedlist-starting-number (with-param name: list select: "parent::*"))))) (template name: next.numeration (param numeration select: 'default') (choose (when "$numeration = 'arabic'" loweralpha) (when "$numeration = 'loweralpha'" lowerroman) (when "$numeration = 'lowerroman'" upperalpha) (when "$numeration = 'upperalpha'" upperroman) (when "$numeration = 'upperroman'" arabic) (otherwise arabic))) (template name: list.numeration (param node select: .) (choose (when $node/@numeration (value-of select: $node/@numeration)) (otherwise (choose (when "$node/ancestor::orderedlist" (call-template name: next.numeration (with-param name: numeration (call-template name: list.numeration (with-param name: node select: "$node/ancestor::orderedlist[1]"))))) (otherwise (call-template name: next.numeration)))))) (template name: next.itemsymbol (param itemsymbol select: 'default') (choose (when "$itemsymbol = 'disc'" circle) (when "$itemsymbol = 'round'" square) (otherwise disc))) (template name: list.itemsymbol (param node select: .) (choose (when $node/@mark (value-of select: $node/@mark)) (otherwise (choose (when "$node/ancestor::itemizedlist" (call-template name: next.itemsymbol (with-param name: itemsymbol (call-template name: list.itemsymbol (with-param name: node select: "$node/ancestor::itemizedlist[1]"))))) (otherwise (call-template name: next.itemsymbol)))))) (lx:namespace ((#f "")) (doc:template name: copyright.years (refpurpose "Print a set of years with collapsed ranges") (refdescription (para "This template prints a list of year elements with consecutive years printed as a range. In other words:") (screen "1992 1993 1994") (para "is printed" (quote 1992-1994) ", whereas:") (screen "1992 1994") (para "is printed" (quote "1992, 1994") .) (para "This template assumes that all the year elements contain only decimal year numbers, that the elements are sorted in increasing numerical order, that there are no duplicates, and that all the years are expressed in full" (quote century+year) "(" (quote 1999) not (quote 99) ") notation.")) (refparameter (variablelist (varlistentry (term years) (listitem (para "The initial set of year elements."))) (varlistentry (term print.ranges) (listitem (para "If non-zero, multi-year ranges are collapsed. If zero, all years are printed discretely."))) (varlistentry (term single.year.ranges) (listitem (para "If non-zero, two consecutive years will be printed as a range, otherwise, they will be printed discretely. In other words, a single year range is" (quote 1991-1992) "but discretely it's" (quote "1991, 1992") .))))) (refreturn (para "This template returns the formatted list of years.")))) (template name: copyright.years (param years) (param print.ranges select: 1) (param single.year.ranges select: 0) (param firstyear select: 0) (param nextyear select: 0) (choose (when "$print.ranges = 0 and count($years) > 0" (choose (when "count($years) = 1" (apply-templates select: "$years[1]" mode: titlepage.mode)) (otherwise (apply-templates select: "$years[1]" mode: titlepage.mode) (text ,) (call-template name: copyright.years (with-param name: years select: "$years[position() > 1]") (with-param name: print.ranges select: $print.ranges) (with-param name: single.year.ranges select: $single.year.ranges))))) (when "count($years) = 0" (variable lastyear select: "$nextyear - 1") (choose (when "$firstyear = 0") (when "$firstyear = $lastyear" (value-of select: $firstyear)) (when "$single.year.ranges = 0 and $lastyear = $firstyear + 1" (value-of select: $firstyear) (text ,) (value-of select: $lastyear)) (otherwise (value-of select: $firstyear) (text -) (value-of select: $lastyear)))) (when "$firstyear = 0" (call-template name: copyright.years (with-param name: years select: "$years[position() > 1]") (with-param name: firstyear select: "$years[1]") (with-param name: nextyear select: "$years[1] + 1") (with-param name: print.ranges select: $print.ranges) (with-param name: single.year.ranges select: $single.year.ranges))) (when "$nextyear = $years[1]" (call-template name: copyright.years (with-param name: years select: "$years[position() > 1]") (with-param name: firstyear select: $firstyear) (with-param name: nextyear select: "$nextyear + 1") (with-param name: print.ranges select: $print.ranges) (with-param name: single.year.ranges select: $single.year.ranges))) (otherwise (choose (when "$nextyear = $firstyear + 1" (value-of select: $firstyear) (text ,)) (when "$single.year.ranges = 0 and $nextyear = $firstyear + 2" (value-of select: $firstyear) (text ,) (value-of select: "$nextyear - 1") (text ,)) (otherwise (value-of select: $firstyear) (text -) (value-of select: "$nextyear - 1") (text ,))) (call-template name: copyright.years (with-param name: years select: "$years[position() > 1]") (with-param name: firstyear select: "$years[1]") (with-param name: nextyear select: "$years[1] + 1") (with-param name: print.ranges select: $print.ranges) (with-param name: single.year.ranges select: $single.year.ranges))))) (lx:namespace ((#f "")) (doc:template name: find.path.params (refpurpose "Search in a table for the \"best\" match for the node") (refdescription (para "This template searches in a table for the value that most-closely (in the typical best-match sense of XSLT) matches the current (element) node location.")))) (template name: find.path.params (param node select: .) (param table select: '') (param location (call-template name: xpath.location (with-param name: node select: $node))) (variable value (call-template name: lookup.key (with-param name: key select: $location) (with-param name: table select: $table))) (choose (when "$value != ''" (value-of select: $value)) (when "contains($location, '/')" (call-template name: find.path.params (with-param name: node select: $node) (with-param name: table select: $table) (with-param name: location select: "substring-after($location, '/')")))))))