You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p><ahref="https://developer.mozilla.org/en-US/docs/Web/SVG">SVG images</a> can be used as stand-alone files, but the
34
+
most efficient way to include them in an HTML document is by embedding them. However, this may cause unexpected problems due to
35
+
two factors:</p>
36
+
<ul>
37
+
<li>Element IDs that were unique in the SVG image and the main document may collide, causing the HTML to become non-conformant
38
+
due to the presence of two (or more) <ahref="https://html.spec.whatwg.org/multipage/introduction.html#restrictions-on-content-models-and-on-attribute-values:the-id-attribute">elements with the same ID</a>.</li>
39
+
<li>The way that <ahref="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style"><code>STYLE</code></a> elements are handled in HTML documents may cause further collisions (see below).</li>
40
+
</ul>
41
+
<p>The <code>STYLE</code> elements contained inside the hierarchy of the <code>SVG</code> elements are used for the
42
+
computation of the styles of the whole document. That is, the rules located in a style sheet that was written for a
43
+
specific SVG image are accounted like if the <code>STYLE</code> was located at the <code>HEAD</code> element (but applying
44
+
the CSS precedence rules).</p>
45
+
<p>Due to that, there could be a collision between IDs and class names in the CSS from the SVG image(s) and the main document,
46
+
or among the embedded SVG images.</p>
47
+
</div>
48
+
<divclass="tema" id="visitor">
49
+
<h2>Using the visitor pattern to replace identifiers</h2>
50
+
<p>Fortunately, the css4j library provides the necessary tools to visit the CSS rules and make the necessary checks and
51
+
modifications to the relevant selectors. You can use your favourite DOM implementation to check and modify duplicate <code>id</code>
52
+
attributes (if you use css4j's <ahref="https://css4j.github.io/api/3/io/sf/carte/doc/dom/package-summary.html">native DOM</a>,
53
+
a <aclass="codeitem" href="https://css4j.github.io/api/3/io/sf/carte/doc/dom/NodeIterator.html"><code>NodeIterator</code></a>
54
+
could be a good choice), but the changes must be consistent with what you apply on the selectors.</p>
0 commit comments