You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在SGML文件中配置基础URL变量以简化链接编写

如何配置基础URL简化SGML中的ulink链接?

我在单个.sgml文件中使用了重复前缀的链接代码:

<ulink url="https://github.com/postgres/postgres/commit/2af07e2f7"> [2af07e2f7] </ulink>
<ulink url="https://github.com/postgres/postgres/commit/165d581f1"> [165d581f1] </ulink>,
<ulink url="https://github.com/postgres/postgres/commit/617f9b7d4"> [617f9b7d4] </ulink>

希望配置一个基础URL变量,将链接简化为以下形式,避免重复编写https://github.com/postgres/postgres/commit前缀:

<ulink url="$variable/2af07e2f7"> [2af07e2f7] </ulink>

当前已有的XSL参数配置如下:

<xsl:param name="base.dir" select="'html/'"></xsl:param>

怀疑该配置可能和需求相关,请问能否实现?


实现方案

可以通过新增自定义XSL参数+改写模板的方式实现,步骤如下:

  1. 添加自定义基础URL参数
    在你的stylesheet.xsl文件中新增一个参数,定义GitHub提交链接的基础前缀:
<xsl:param name="github.commit.base.url" select="'https://github.com/postgres/postgres/commit/'" />
  1. 编写ulink匹配模板
    添加一个模板来处理ulink标签,自动识别简化写法并拼接完整URL:
<xsl:template match="ulink">
  <xsl:variable name="raw-url" select="@url" />
  <xsl:choose>
    <!-- 匹配以$github/开头的简化链接 -->
    <xsl:when test="starts-with($raw-url, '$github/')">
      <ulink>
        <xsl:attribute name="url">
          <xsl:value-of select="concat($github.commit.base.url, substring-after($raw-url, '$github/'))" />
        </xsl:attribute>
        <xsl:apply-templates />
      </ulink>
    </xsl:when>
    <!-- 保留原有正常链接的处理逻辑 -->
    <xsl:otherwise>
      <xsl:copy-of select="." />
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
  1. 使用简化写法
    之后在sgml文件中就可以用简化形式编写链接:
<ulink url="$github/2af07e2f7"> [2af07e2f7] </ulink>
<ulink url="$github/165d581f1"> [165d581f1] </ulink>,
<ulink url="$github/617f9b7d4"> [617f9b7d4] </ulink>

注意:原有的base.dir参数仅用于指定HTML输出文件的存放目录,和URL拼接需求无关,需要通过新增自定义参数实现目标功能。

内容的提问来源于stack exchange,提问作者jian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 21:41:18