mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 09:05:30 +00:00
Export xsl into seperate file via embedding
This commit is contained in:
@@ -1,35 +1,50 @@
|
||||
const p = "[xslt-onload]", T = "xslt-template", i = "xslt-transformed";
|
||||
function a(c) {
|
||||
let o = document.querySelectorAll(p);
|
||||
for (let e of o) {
|
||||
if (e.getAttribute(i) === "true")
|
||||
continue;
|
||||
let r = e.getAttribute(T), t = htmx.find("#" + r);
|
||||
if (t) {
|
||||
let l = t.innerHTML ? new DOMParser().parseFromString(t.innerHTML, "application/xml") : t.contentDocument, s = new XSLTProcessor();
|
||||
s.importStylesheet(l);
|
||||
let n = new DOMParser().parseFromString(e.innerHTML, "application/xml"), m = s.transformToFragment(n, document), u = new XMLSerializer().serializeToString(m);
|
||||
e.innerHTML = u, e.setAttribute(i, !0);
|
||||
} else
|
||||
throw new Error("Unknown XSLT template: " + r);
|
||||
}
|
||||
const u = "[xslt-onload]", f = "xslt-template", a = "xslt-transformed", c = "xslt-remote-template";
|
||||
function h() {
|
||||
let t = htmx.findAll(u);
|
||||
for (let n of t)
|
||||
d(n);
|
||||
}
|
||||
function d() {
|
||||
a(), htmx.on("htmx:load", a), document.querySelectorAll("template[simple]").forEach((o) => {
|
||||
let e = o.getAttribute("id"), r = o.content;
|
||||
function d(t) {
|
||||
if (t.getAttribute(a) === "true")
|
||||
return;
|
||||
let n = t.getAttribute(f), o = htmx.find("#" + n);
|
||||
if (o) {
|
||||
let s = o.innerHTML ? new DOMParser().parseFromString(o.innerHTML, "application/xml") : o.contentDocument;
|
||||
console.log(s);
|
||||
let l = new XSLTProcessor();
|
||||
l.importStylesheet(s);
|
||||
let e = new DOMParser().parseFromString(t.innerHTML, "application/xml"), i = l.transformToFragment(e, document), r = new XMLSerializer().serializeToString(i);
|
||||
t.innerHTML = r, t.setAttribute(a, !0);
|
||||
} else if (t.hasAttribute(c)) {
|
||||
let s = t.getAttribute(c), l = new Request(s, {
|
||||
headers: { "Content-Type": "application/xslt+xml" },
|
||||
cache: "default"
|
||||
});
|
||||
fetch(l).then((e) => e.text()).then((e) => {
|
||||
let i = new DOMParser().parseFromString(e, "application/xslt+xml"), r = new XSLTProcessor();
|
||||
r.importStylesheet(i);
|
||||
let p = new DOMParser().parseFromString(t.innerHTML, "application/xml"), T = r.transformToFragment(p, document), m = new XMLSerializer().serializeToString(T);
|
||||
t.innerHTML = m, t.setAttribute(a, !0);
|
||||
});
|
||||
} else
|
||||
throw new Error("Unknown XSLT template: " + n);
|
||||
}
|
||||
function S() {
|
||||
h(), document.querySelectorAll("template[simple]").forEach((n) => {
|
||||
let o = n.getAttribute("id"), s = n.content;
|
||||
customElements.define(
|
||||
e,
|
||||
o,
|
||||
class extends HTMLElement {
|
||||
constructor() {
|
||||
super(), this.appendChild(r.cloneNode(!0)), this.slots = this.querySelectorAll("slot");
|
||||
super(), this.appendChild(s.cloneNode(!0)), this.slots = this.querySelectorAll("slot");
|
||||
}
|
||||
connectedCallback() {
|
||||
let t = [];
|
||||
this.slots.forEach((l) => {
|
||||
let s = l.getAttribute("name"), n = this.querySelector(`[slot="${s}"]`);
|
||||
n && (l.replaceWith(n.cloneNode(!0)), t.push(n));
|
||||
}), t.forEach((l) => {
|
||||
l.remove();
|
||||
let l = [];
|
||||
this.slots.forEach((e) => {
|
||||
let i = e.getAttribute("name"), r = this.querySelector(`[slot="${i}"]`);
|
||||
r && (e.replaceWith(r.cloneNode(!0)), l.push(r));
|
||||
}), l.forEach((e) => {
|
||||
e.remove();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -37,5 +52,5 @@ function d() {
|
||||
});
|
||||
}
|
||||
export {
|
||||
d as setup
|
||||
S as setup
|
||||
};
|
||||
|
||||
13
views/assets/xslt/citation.xsl
Normal file
13
views/assets/xslt/citation.xsl
Normal file
@@ -0,0 +1,13 @@
|
||||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<xsl:output method="html" indent="yes" />
|
||||
<xsl:template match="title">
|
||||
<em>
|
||||
<xsl:apply-templates />
|
||||
</em>
|
||||
</xsl:template>
|
||||
<xsl:template match="year">
|
||||
<span class="">
|
||||
<xsl:apply-templates />
|
||||
</span>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>
|
||||
Reference in New Issue
Block a user