Skip to content

Commit 5516c21

Browse files
committed
Update HTML processing section to consider HTML base element, and note about prospect of dynamically changing base. This reflects discussion from #23 (comment) and resulting TAG advice w3ctag/design-reviews#312 (comment).
1 parent c1cac18 commit 5516c21

17 files changed

+171
-13
lines changed

common/extract-examples.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,11 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:)
319319
$stdout.write "F".colorize(:red)
320320
next
321321
end
322+
323+
# Get base from document, if present
324+
html_base = doc.at_xpath('/html/head/base/@href')
325+
ex[:base] = html_base.to_s if html_base
326+
322327
script_content = doc.at_xpath(xpath)
323328
if script_content
324329
# Remove (faked) XML comments and unescape sequences
@@ -439,6 +444,11 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:)
439444
args[0] = if examples[ex[:result_for]][:ext] == 'html' && method == :expand
440445
# If we are expanding, and the reference is HTML, find the first script element.
441446
doc = Nokogiri::HTML.parse(examples[ex[:result_for]][:content])
447+
448+
# Get base from document, if present
449+
html_base = doc.at_xpath('/html/head/base/@href')
450+
options[:base] = html_base.to_s if html_base
451+
442452
script_content = doc.at_xpath(xpath)
443453
unless script_content
444454
errors << "Example #{ex[:number]} at line #{ex[:line]} references example #{ex[:result_for].inspect} with no JSON-LD script element"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[{
2+
"@id": "http://dbpedia.org/resource/John_Lennon",
3+
"http://xmlns.com/foaf/0.1/name": [{"@value": "John Lennon"}],
4+
"http://schema.org/birthDate": [
5+
{"@value": "1940-10-09", "@type": "http://www.w3.org/2001/XMLSchema#date"}
6+
],
7+
"http://schema.org/spouse": [
8+
{"@id": "http://dbpedia.org/resource/Cynthia_Lennon"}
9+
]
10+
}]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
{
3+
"@context": "https://json-ld.org/contexts/person.jsonld",
4+
"@id": "John_Lennon",
5+
"name": "John Lennon",
6+
"born": "1940-10-09",
7+
"spouse": "Cynthia_Lennon"
8+
}
9+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<table class="statements" data-result-for="Using the document base URL to establish the default base IRI-expanded" data-to-rdf>
2+
<thead><tr>
3+
<th>Subject</th>
4+
<th>Property</th>
5+
<th>Value</th>
6+
<th>Value Type</th>
7+
</tr></thead>
8+
<tbody>
9+
<tr>
10+
<td>http://dbpedia.org/resource/John_Lennon</td>
11+
<td>foaf:name</td>
12+
<td>John Lennon</td>
13+
<td> </td>
14+
</tr>
15+
<tr>
16+
<td>http://dbpedia.org/resource/John_Lennon</td>
17+
<td>schema:birthDate</td>
18+
<td>1940-10-09</td>
19+
<td>xsd:date</td>
20+
</tr>
21+
<tr>
22+
<td>http://dbpedia.org/resource/John_Lennon</td>
23+
<td>schema:spouse</td>
24+
<td>http://dbpedia.org/resource/Cynthia_Lennon</td>
25+
<td> </td>
26+
</tr>
27+
</tbody>
28+
</table>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@base <http://dbpedia.org/resource/> .
2+
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
3+
@prefix schema: <http://schema.org/> .
4+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
5+
<John_Lennon> foaf:name "John Lennon";
6+
schema:birthDate "1940-10-09"^^xsd:date;
7+
schema:spouse <Cynthia_Lennon> .

index.html

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8482,7 +8482,9 @@ <h3>Graph Containers</h3>
84828482
<p>If JSON-LD content is extracted as RDF [[RDF11-CONCEPTS]], it MUST be expanded into an
84838483
<a>RDF Dataset</a> using the
84848484
<a data-cite="JSON-LD11-API#deserialize-json-ld-to-rdf-algorithm">Deserialize JSON-LD to RDF Algorithm</a>
8485-
[[JSON-LD11-API]]. All <a data-cite="HTML52/semantics-scripting.html#the-script-element">script elements</a>
8485+
[[JSON-LD11-API]]. Unless a specific script is targeted
8486+
(see <a href="#locating-a-specific-json-ld-script-element" class="sectionRef"></a>),
8487+
all <a data-cite="HTML52/semantics-scripting.html#the-script-element">script elements</a>
84868488
with <code>type</code> <code>application/ld+json</code> MUST be processed and merged
84878489
into a single <a>dataset</a> with equivalent <a>blank node identifiers</a> contained in
84888490
separate script elements treated as if they were in a single document (i.e.,
@@ -8558,10 +8560,92 @@ <h3>Graph Containers</h3>
85588560

85598561
<p>When processing a JSON-LD
85608562
<a data-cite="HTML52/semantics-scripting.html#the-script-element">script element</a>,
8561-
only the resolved document location of the
8562-
containing HTML document is used to establish the default <a>base IRI</a> of the enclosed
8563+
the <a data-cite="HTML52/infrastructure.html#document-base-url">Document Base URL</a>
8564+
of the containing HTML document,
8565+
as defined in [[HTML52]],
8566+
is used to establish the default <a>base IRI</a> of the enclosed
85638567
JSON-LD content.</p>
85648568

8569+
<aside class="example ds-selector-tabs"
8570+
title="Using the document base URL to establish the default base IRI">
8571+
<div class="selectors">
8572+
<button class="selected" data-selects="original">Original</button>
8573+
<button data-selects="expanded">Expanded</button>
8574+
<button data-selects="statements">Statements</button>
8575+
<button data-selects="turtle">Turtle</button>
8576+
</div>
8577+
<pre class="original selected" data-transform="updateExample"
8578+
data-content-type="text/html">
8579+
<!--
8580+
****<html>
8581+
<head>
8582+
<base href="http://dbpedia.org/resource/"/>****
8583+
<script type="application/ld+json">
8584+
< !--
8585+
{
8586+
"@context": "https://json-ld.org/contexts/person.jsonld",
8587+
"@id": ****"John_Lennon"****,
8588+
"name": "John Lennon",
8589+
"born": "1940-10-09",
8590+
"spouse": ****"Cynthia_Lennon"****
8591+
}
8592+
-- >
8593+
</script>
8594+
****</head>
8595+
</html>****
8596+
-->
8597+
</pre>
8598+
<pre class="expanded"
8599+
data-transform="updateExample"
8600+
data-result-for="Using the document base URL to establish the default base IRI-original">
8601+
<!--
8602+
[{
8603+
"@id": "http://dbpedia.org/resource/John_Lennon",
8604+
"http://xmlns.com/foaf/0.1/name": [{"@value": "John Lennon"}],
8605+
"http://schema.org/birthDate": [
8606+
{"@value": "1940-10-09", "@type": "http://www.w3.org/2001/XMLSchema#date"}
8607+
],
8608+
"http://schema.org/spouse": [
8609+
{"@id": "http://dbpedia.org/resource/Cynthia_Lennon"}
8610+
]
8611+
}]
8612+
-->
8613+
</pre>
8614+
<table class="statements"
8615+
data-result-for="Using the document base URL to establish the default base IRI-expanded"
8616+
data-to-rdf>
8617+
<thead><tr><th>Subject</th><th>Property</th><th>Value</th><th>Value Type</th></tr></thead>
8618+
<tbody>
8619+
<tr><td>http://dbpedia.org/resource/John_Lennon</td><td>foaf:name</td><td>John Lennon</td><td>&nbsp;</td></tr>
8620+
<tr><td>http://dbpedia.org/resource/John_Lennon</td><td>schema:birthDate</td><td>1940-10-09</td><td>xsd:date</td></tr>
8621+
<tr><td>http://dbpedia.org/resource/John_Lennon</td><td>schema:spouse</td><td>http://dbpedia.org/resource/Cynthia_Lennon</td><td>&nbsp;</td></tr>
8622+
</tbody>
8623+
</table>
8624+
<pre class="turtle"
8625+
data-content-type="text/turtle"
8626+
data-transform="updateExample"
8627+
data-result-for="Using the document base URL to establish the default base IRI-expanded"
8628+
data-to-rdf>
8629+
<!--
8630+
@base <http://dbpedia.org/resource/> .
8631+
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
8632+
@prefix schema: <http://schema.org/> .
8633+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
8634+
8635+
<John_Lennon> foaf:name "John Lennon";
8636+
schema:birthDate "1940-10-09"^^xsd:date;
8637+
schema:spouse <Cynthia_Lennon> .
8638+
-->
8639+
</pre>
8640+
</aside>
8641+
8642+
<p>HTML allows for <a data-cite="HTML52/infrastructure.html#dynamic-changes-to-base-urls">Dynamic changes to base URLs</a>.
8643+
This specification does not require any specific behavior,
8644+
and to ensure that all systems process the <a>base IRI</a> equivalently, authors SHOULD
8645+
either use <a>absolute IRIs</a>, or explicitly as defined in <a href="#base-iri" class="sectionRef"></a>.
8646+
Implementations (particularly those natively operating in the [[!DOM]]) MAY take into consideration
8647+
<a data-cite="HTML52/infrastructure.html#dynamic-changes-to-base-urls">Dynamic changes to base URLs</a>.</p>
8648+
85658649
<section><h3>Locating a Specific JSON-LD Script Element</h3>
85668650
<p>A specific
85678651
<a data-cite="HTML52/semantics-scripting.html#the-script-element">script element</a>

yaml/Flattened-and-expanded-form-for-the-previous-example.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Example 108: Flattened and expanded form for the previous example
1+
Example 109: Flattened and expanded form for the previous example
22
---
33
- "@id": _:b0
44
http://xmlns.com/foaf/0.1/name: Dave Longley

yaml/JSON-LD-using-native-data-types-for-numbers-and-boolean-values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Example 114: JSON-LD using native data types for numbers and boolean values
1+
Example 115: JSON-LD using native data types for numbers and boolean values
22
---
33
"@context":
44
ex: http://example.com/vocab#

yaml/Linked-Data-Dataset-compacted.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Example 106: Linked Data Dataset-compacted
1+
Example 107: Linked Data Dataset-compacted
22
---
33
"@context":
44
- http://schema.org/

yaml/Linked-Data-Dataset-expanded.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Example 106: Linked Data Dataset-expanded
1+
Example 107: Linked Data Dataset-expanded
22
---
33
- "@id": http://example.com/people/alice
44
http://schema.org/name:

yaml/Same-book-description-in-JSON-LD-avoiding-contexts-.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Example 121: Same book description in JSON-LD (avoiding contexts)
1+
Example 122: Same book description in JSON-LD (avoiding contexts)
22
---
33
- "@id": http://purl.oreilly.com/works/45U8QJGZSQKDH8N
44
"@type": http://purl.org/vocab/frbr/core#Work

yaml/Same-description-in-JSON-LD-context-shared-among-node-objects-.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Example 119: Same description in JSON-LD (context shared among node objects)
1+
Example 120: Same description in JSON-LD (context shared among node objects)
22
---
33
"@context":
44
foaf: http://xmlns.com/foaf/0.1/

yaml/Same-embedding-example-in-JSON-LD.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Example 113: Same embedding example in JSON-LD
1+
Example 114: Same embedding example in JSON-LD
22
---
33
"@context":
44
foaf: http://xmlns.com/foaf/0.1/

yaml/Same-example-with-a-list-of-values-in-JSON-LD.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Example 117: Same example with a list of values in JSON-LD
1+
Example 118: Same example with a list of values in JSON-LD
22
---
33
"@context":
44
foaf: http://xmlns.com/foaf/0.1/

yaml/Sample-JSON-LD-document.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Example 107: Sample JSON-LD document
1+
Example 108: Sample JSON-LD document
22
---
33
"@context":
44
name: http://xmlns.com/foaf/0.1/name

yaml/The-same-set-of-statements-serialized-in-JSON-LD.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Example 111: The same set of statements serialized in JSON-LD
1+
Example 112: The same set of statements serialized in JSON-LD
22
---
33
"@context":
44
foaf: http://xmlns.com/foaf/0.1/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Example 104: Using the document base URL to establish the default base IRI-expanded
2+
---
3+
- "@id": http://dbpedia.org/resource/John_Lennon
4+
http://xmlns.com/foaf/0.1/name:
5+
- "@value": John Lennon
6+
http://schema.org/birthDate:
7+
- "@value": '1940-10-09'
8+
"@type": http://www.w3.org/2001/XMLSchema#date
9+
http://schema.org/spouse:
10+
- "@id": http://dbpedia.org/resource/Cynthia_Lennon

0 commit comments

Comments
 (0)