be-restated is one of a trio of element decorators / behaviors that takes advantage of the buried treasure that is XSLT, built into the browser.
The differences are summarized in the table below.
Bottom line, be-restated focuses on the following problem statements:
- Extracting the data from server-rendered HTML, in partnership with obj-xml.
- Providing derived content from other content. For example, generating a table of contents based on the contents of the page.
Decorator/behavior | Problem statements | Notes |
---|---|---|
be-restated |
|
|
be-metamorphic |
|
|
be-ferried |
|
<table-of-contents be-restated='{
"from": "main",
"xslt": "toc.xslt"
}'>
</table-of-contents>
...
<main>
<h1>Heading 1</h1>
<section>
<h2>Heading 2</h2>
</section>
<section>...</section>
<template be-a-beacon></template>
</main>
What this does:
- If be-restated can't locate main, it attaches an event handler to the host or document.body, listening for the event be-a-beacon emits: "i-am-here". Every time such an event occurs, searches the host's Shadow DOM, or document.body for element "main".
- Once element "main" is found, moves the beacon event listener to the main element.
- If the template[be-a-beacon] element is found, xslt is performed with the content of the main element, and the table-of-contents light children are populated from the result.
- If the event handler on the main element picks up "i-am-here" messages going forward, it re-does step 3.