XLink 1.1 完整参考手册(2025 年实用版)
命名空间(永远不变)
xmlns:xlink="http://www.w3.org/1999/xlink"
1. 六种 xlink:type 值(全部)
| xlink:type 值 | 用途 | 必须出现的属性 | 常用可选属性 |
|---|---|---|---|
| simple | 相当于 HTML <a> 或 <img> | xlink:href | show, actuate, title, role, arcrole |
| extended | 扩展链接容器(可放多个 locator/arc) | 无(本身是容器) | — |
| locator | 指向外部资源(扩展链接的“端点”) | xlink:href + xlink:label | role, title |
| arc | 定义从 A → B 的遍历规则 | xlink:from + xlink:to | arcrole, show, actuate, title |
| resource | 本地资源(扩展链接的“端点”) | xlink:label | role, title |
| title | 为整个 extended link 或 arc 提供标题 | 无 | — |
2. 全部属性速查表
| 属性 | 适用类型 | 取值示例 | 说明 |
|---|---|---|---|
| xlink:type | 所有 XLink 元素(必填) | simple / extended / locator / arc / resource / title | 决定元素是哪种链接类型 |
| xlink:href | simple、locator | “doc.xml#chap3” 、 “photo.jpg” 、 “mailto:a@b.com” | 目标 URI,可含 XPointer |
| xlink:role | simple、locator、resource | “http://purl.org/dc/terms/creator” | 语义角色(任意 URI) |
| xlink:arcrole | simple、arc | “http://example.org/rel#parent-of” | 弧的语义(为什么从 A 到 B) |
| xlink:title | 所有类型 | “查看第三章”、”父亲→儿子” | 提示文字或可访问标题 |
| xlink:show | simple、arc | new / replace / embed / other / none | 如何显示目标 |
| xlink:actuate | simple、arc | onRequest / onLoad / other / none | 何时激活链接 |
| xlink:label | locator、resource | “john”、”photo1” | 供 arc 的 from/to 引用 |
| xlink:from | arc | 与某个 xlink:label 同名 | 起点 |
| xlink:to | arc | 与某个 xlink:label 同名 | 终点 |
3. show 与 actuate 组合速记表(最常用 5 种)
| 想要的效果 | xlink:show | xlink:actuate | 典型场景 |
|---|---|---|---|
| 普通网页跳转 | replace | onRequest | 文本链接 |
| 新窗口打开 | new | onRequest | 常见“外部链接” |
| 直接显示图片/多媒体 | embed | onLoad | |
| 鼠标悬停时加载(少用) | embed | onRequest | 悬停预览 |
| 文档加载时自动跳转 | replace | onLoad | 自动重定向 |
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 项目时再也不用查文档了。