XLink 参考手册

XLink 1.1 完整参考手册(2025 年实用版)

命名空间(永远不变)

xmlns:xlink="http://www.w3.org/1999/xlink"

1. 六种 xlink:type 值(全部)

xlink:type 值用途必须出现的属性常用可选属性
simple相当于 HTML <a><img>xlink:hrefshow, actuate, title, role, arcrole
extended扩展链接容器(可放多个 locator/arc)无(本身是容器)
locator指向外部资源(扩展链接的“端点”)xlink:href + xlink:labelrole, title
arc定义从 A → B 的遍历规则xlink:from + xlink:toarcrole, show, actuate, title
resource本地资源(扩展链接的“端点”)xlink:labelrole, title
title为整个 extended link 或 arc 提供标题

2. 全部属性速查表

属性适用类型取值示例说明
xlink:type所有 XLink 元素(必填)simple / extended / locator / arc / resource / title决定元素是哪种链接类型
xlink:hrefsimple、locator“doc.xml#chap3” 、 “photo.jpg” 、 “mailto:a@b.com”目标 URI,可含 XPointer
xlink:rolesimple、locator、resource“http://purl.org/dc/terms/creator”语义角色(任意 URI)
xlink:arcrolesimple、arc“http://example.org/rel#parent-of”弧的语义(为什么从 A 到 B)
xlink:title所有类型“查看第三章”、”父亲→儿子”提示文字或可访问标题
xlink:showsimple、arcnew / replace / embed / other / none如何显示目标
xlink:actuatesimple、arconRequest / onLoad / other / none何时激活链接
xlink:labellocator、resource“john”、”photo1”供 arc 的 from/to 引用
xlink:fromarc与某个 xlink:label 同名起点
xlink:toarc与某个 xlink:label 同名终点

3. show 与 actuate 组合速记表(最常用 5 种)

想要的效果xlink:showxlink:actuate典型场景
普通网页跳转replaceonRequest文本链接
新窗口打开newonRequest常见“外部链接”
直接显示图片/多媒体embedonLoad
鼠标悬停时加载(少用)embedonRequest悬停预览
文档加载时自动跳转replaceonLoad自动重定向

4. 官方推荐的最小完整示例(W3C 规范原文摘录)

<!-- 1. 简单链接(最常用)-->
<go xlink:type="simple"
    xlink:href="students.xml"
    xlink:role="http://example.com/role#studentList"
    xlink:title="学生名单"
    xlink:show="replace"
    xlink:actuate="onRequest"/>

<!-- 2. 完整扩展链接(最强大)-->
<mylink xmlns:xlink="http://www.w3.org/1999/xlink"
        xlink:type="extended">
  <loc xlink:type="locator" xlink:href="student.xml#bob"   xlink:label="bob"   xlink:title="Bob"/>
  <loc xlink:type="locator" xlink:href="student.xml#alice" xlink:label="alice" xlink:title="Alice"/>
  <res xlink:type="resource" xlink:label="greeting">Hello!</res>
  <arc xlink:type="arc" xlink:from="greeting" xlink:to="bob"   xlink:show="replace"/>
  <arc xlink:type="arc" xlink:from="greeting" xlink:to="alice" xlink:show="replace"/>
  <tit xlink:type="title">问候链接集</tit>
</mylink>

5. 2025 年真实项目中最常见的 8 种写法(直接复制)

<!-- 1. 普通文本链接(90% 的情况)-->
<ref xlink:type="simple" xlink:href="chap2.xml#intro"/>

<!-- 2. 新窗口打开-->
<link xlink:type="simple" xlink:href="https://w3.org/TR/xlink/" xlink:show="new"/>

<!-- 3. 嵌入图片(SVG、XHTML 中常用)-->
<image xlink:type="simple" xlink:href="cat.jpg" xlink:show="embed" xlink:actuate="onLoad"/>

<!-- 4. EPUB 3 脚注(出版标配)-->
<a xlink:type="simple" xlink:href="notes.xhtml#n001"/>

<!-- 5. SVG 内部引用(天天用)-->
<use xlink:href="#mySymbol"/>

<!-- 6. 带语义的学术引用-->
<citation xlink:type="simple"
          xlink:href="https://doi.org/10.1000/xyz123"
          xlink:role="http://purl.org/spar/cito/cites"
          xlink:arcrole="http://purl.org/spar/cito/citesAsAuthority"/>

<!-- 7. 第三方关系库(最强大功能)-->
<relationships xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="extended">
  <loc xlink:type="locator" xlink:href="hamlet.xml#hamlet" xlink:label="hamlet"/>
  <loc xlink:type="locator" xlink:href="shakespeare.xml#shak" xlink:label="shak"/>
  <arc xlink:type="arc" xlink:from="shak" xlink:to="hamlet"
       xlink:arcrole="http://example.org/rel#author"/>
</relationships>

<!-- 8. 回链(双向链接)-->
<back xmlns:xlink="http://www.w3.org/1999/xlink"
      xlink:type="simple"
      xlink:href="chapter1.xhtml#ftn23">返回正文</back>

官方规范地址(永久有效)

  • XLink 1.1(最新):https://www.w3.org/TR/xlink11/
  • XLink 1.0(历史):https://www.w3.org/TR/xlink/

把这张表保存为 xlink-cheat-sheet.xml 或打印出来贴墙上,写任何 XML、SVG、EPUB、TEI 项目时再也不用查文档了。

文章已创建 2783

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部