On 17.01.2023 at 23:43, Karl O. Pinc wrote:
It's good you asked. After poking about the XSLT 1.0 spec to refresh my memory I abandoned the "mode" approach entirely. The real "right way" is to use the import mechanism.
It actually is not. After quite some time trying to figure out why things don't work as intended, I ended up reading the XSLT 1.0 spec. As the name already suggests, <xsl:apply-imports> is closely related to <xsl:apply-templates> with the difference that it *applies* a *template rule* from an imported style sheet instead of applying a template rule from the current style sheet (https://www.w3.org/TR/1999/REC-xslt-19991116#apply-imports). What it does not do is *calling* a *named template* (https://www.w3.org/TR/1999/REC-xslt-19991116#named-templates). What this basically means is that in XSLT 1.0 you can use <xsl:apply-imports> to override template rules (<xsl:template match="this-pattern-inside-match-makes-it-a-template-rule">) but you cannot use it to override named templates (<xsl:template name="this-id-inside-name-makes-it-a-named-template">). If you want to override named templates you basically have to duplicate and change them. While there are mechanisms to call overriden named templates in XSLT 3, this is out of scope here, since we're bound to XSLT 1.0 As a consequence, there was little I could change in the initial patch to avoid the code duplication and all attempts to do so, ultimately led to even longer and more complex code without really reducing the amount of duplication. The <xsl:apply-imports> approach actually does work in the varlistentry case, although this doesn't really change a lot regarding the length of the patch (it's a bit nicer though since in this case it really avoids duplication). I've also taken the advice to terminate the build and print the xpath if a required id is missing. The attached patch is my best-effort approach to implement discoverable links. Best regards, Brar
diff --git a/doc/src/sgml/pgwalinspect.sgml b/doc/src/sgml/pgwalinspect.sgml index 62d9f9eb22..9a0241a8d6 100644 --- a/doc/src/sgml/pgwalinspect.sgml +++ b/doc/src/sgml/pgwalinspect.sgml @@ -157,7 +157,7 @@ combined_size_percentage | 2.8634072910530795 </listitem> </varlistentry> - <varlistentry id="pgwalinspect-funcs-pg-get-wal-block-info"> + <varlistentry> <term> <function>pg_get_wal_block_info(start_lsn pg_lsn, end_lsn pg_lsn) returns setof record</function> </term> diff --git a/doc/src/sgml/stylesheet-html-common.xsl b/doc/src/sgml/stylesheet-html-common.xsl index 3f85ea9536..9df2782ce4 100644 --- a/doc/src/sgml/stylesheet-html-common.xsl +++ b/doc/src/sgml/stylesheet-html-common.xsl @@ -301,120 +301,4 @@ set toc,title </xsl:choose> </xsl:template> -<!-- Override the standard section heading generation to add an id link --> -<xsl:template name="section.heading"> - <xsl:param name="section" select="."/> - <xsl:param name="level" select="1"/> - <xsl:param name="allow-anchors" select="1"/> - <xsl:param name="title"/> - <xsl:param name="class" select="'title'"/> - - <xsl:variable name="id"> - <xsl:choose> - <!-- Make sure the subtitle doesn't get the same id as the title --> - <xsl:when test="self::subtitle"> - <xsl:call-template name="object.id"> - <xsl:with-param name="object" select="."/> - </xsl:call-template> - </xsl:when> - <!-- if title is in an *info wrapper, get the grandparent --> - <xsl:when test="contains(local-name(..), 'info')"> - <xsl:call-template name="object.id"> - <xsl:with-param name="object" select="../.."/> - </xsl:call-template> - </xsl:when> - <xsl:otherwise> - <xsl:call-template name="object.id"> - <xsl:with-param name="object" select=".."/> - </xsl:call-template> - </xsl:otherwise> - </xsl:choose> - </xsl:variable> - - <!-- HTML H level is one higher than section level --> - <xsl:variable name="hlevel"> - <xsl:choose> - <!-- highest valid HTML H level is H6; so anything nested deeper - than 5 levels down just becomes H6 --> - <xsl:when test="$level > 5">6</xsl:when> - <xsl:otherwise> - <xsl:value-of select="$level + 1"/> - </xsl:otherwise> - </xsl:choose> - </xsl:variable> - <xsl:element name="h{$hlevel}" namespace="http://www.w3.org/1999/xhtml"> - <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute> - <xsl:if test="$css.decoration != '0'"> - <xsl:if test="$hlevel<3"> - <xsl:attribute name="style">clear: both</xsl:attribute> - </xsl:if> - </xsl:if> - <xsl:if test="$allow-anchors != 0"> - <xsl:call-template name="anchor"> - <xsl:with-param name="node" select="$section"/> - <xsl:with-param name="conditional" select="0"/> - </xsl:call-template> - </xsl:if> - <xsl:copy-of select="$title"/> - <xsl:call-template name="pg.id.link"> - <xsl:with-param name="object" select="$section"/> - </xsl:call-template> - </xsl:element> -</xsl:template> - -<!-- Override the standard varlistentry/term generation to add an id link - after the last term --> -<xsl:template match="varlistentry/term"> - <xsl:apply-imports/> - <xsl:if test="position() = last()"> - <xsl:call-template name="pg.id.link"> - <xsl:with-param name="object" select="parent::varlistentry"/> - </xsl:call-template> - </xsl:if> -</xsl:template> - -<!-- Creates a link pointing to an id within the document --> -<xsl:template name="pg.id.link"> - <xsl:param name="object" select="."/> - <xsl:choose> - <xsl:when test="$object/@id or $object/@xml:id"> - <a> - <xsl:attribute name="href"> - <xsl:text>#</xsl:text> - <xsl:call-template name="object.id"> - <xsl:with-param name="object" select="$object"/> - </xsl:call-template> - </xsl:attribute> - <xsl:attribute name="class"> - <xsl:text>id_link</xsl:text> - </xsl:attribute> - <xsl:text> #</xsl:text> - </a> - </xsl:when> - <xsl:otherwise> - <!-- Only complain about varlistentries if at least one entry in the list has an id --> - <xsl:if test="name($object) != 'varlistentry' or $object/parent::variablelist/varlistentry[@id]"> - <xsl:message terminate="yes"> - <xsl:text>A </xsl:text> - <xsl:value-of select ="name($object)"/> - <xsl:text> element at path '</xsl:text> - <xsl:for-each select="$object/ancestor::*"> - <xsl:text>/</xsl:text> - <xsl:value-of select ="name(.)"/> - <xsl:if test="@id|@xml:id"> - <xsl:text>[@</xsl:text> - <xsl:value-of select ="name(@id|@xml:id)"/> - <xsl:text> = '</xsl:text> - <xsl:value-of select ="@id"/> - <xsl:text>']</xsl:text> - </xsl:if> - </xsl:for-each> - <xsl:text>' is missing an id. Please add one to make it usable</xsl:text> - <xsl:text> as stable anchor in the public HTML documentation.</xsl:text> - </xsl:message> - </xsl:if> - </xsl:otherwise> - </xsl:choose> -</xsl:template> - </xsl:stylesheet> diff --git a/doc/src/sgml/stylesheet.css b/doc/src/sgml/stylesheet.css index 15bcc95d41..cc14efa1ca 100644 --- a/doc/src/sgml/stylesheet.css +++ b/doc/src/sgml/stylesheet.css @@ -169,13 +169,3 @@ acronym { font-style: inherit; } width: 75%; } } - -/* Links to ids of headers and definition terms */ -a.id_link { - color: inherit; - visibility: hidden; -} - -*:hover > a.id_link { - visibility: visible; -}