On 09/29/2017 03:40 PM, [email protected] wrote:
I target sematic epub output and in that output would like to get the footnote 
text as *plain text* surrounded with *plain text* [footnote] … [/footnote].

 So in your words:  semantic epub  with “Transforming the footnote callout and the 
footnote body to inline "[footnote] … [/footnote]" markup”

No way to get the script from you?


Here it is:

---
namespace "http://www.w3.org/1999/xhtml";;
namespace html = "http://www.w3.org/1999/xhtml";;
namespace g = "urn:x-mlmind:namespace:group";

for-each /html/body//a[get-class("^role-((foot)|(end))note-ref$") and
                       starts-with(@href, "#")] {
    set-variable("fnId", substring-after(@href, "#"));
set-variable("fn", /html/body//div[get-class("^role-((foot)|(end))note$")
                                       and @id=$fnId]);

    if count($fn) = 1 {
        insert-before(<g:envelope>[footnote]</g:envelope>);

        set-variable("fnRef", .);
        set-variable("firstChildP", true());
        for-each $fn/node() {
            set-variable("child", .);
            delete();

            if $child/self::html:p {
                set-element-name("html:span", $child);

                set-variable("childClasses", get-class("", $child));
                if $childClasses {
                    set-attribute("class", $childClasses, $child);
                }

                if $firstChildP {
                    set-variable("firstChildP", false());
                } else {
                    insert-before(<br/>, $fnRef);
                }
            }

            insert-before($child, $fnRef);
        }

        insert-before(<g:envelope>[/footnote]</g:envelope>);

        delete();
    }
}

for-each /html/body//div[get-class("^role-((foot)|(end))notes$")] {
    delete();
}
---

It's used like this (*sample* w2x options file generating semantic EPUB; please do not use it in production):

---
-pu edit.after.footnotes "inline_footnotes.xed"
-p epub.split-before-level 0
-p epub.use-id-as-filename no
-p epub.identifier ""
-o epub1_1
---
(inline_footnotes.xed and inline_footnotes.txt found in the same directory.)

(Corresponding files attached to this email.)

Please note that:

1) As we were not paid to write this XED script, we just tested it against our manual.docx. You are now on your own to actually use or to improve this script.

2) If some of your footnotes contains tables, the generated EPUB will be invalid.

3) The XHTML contained in the generated inline "[footnote] … [/footnote]" markup cannot be "as semantic" as it is elsewhere. I mean, generating inline "[footnote] … [/footnote]" markup is somewhat a *lossy* operation.





namespace "http://www.w3.org/1999/xhtml";;
namespace html = "http://www.w3.org/1999/xhtml";;
namespace g = "urn:x-mlmind:namespace:group";

for-each /html/body//a[get-class("^role-((foot)|(end))note-ref$") and 
                       starts-with(@href, "#")] {
    set-variable("fnId", substring-after(@href, "#"));
    set-variable("fn", /html/body//div[get-class("^role-((foot)|(end))note$") 
                                       and @id=$fnId]);

    if count($fn) = 1 {
        insert-before(<g:envelope>[footnote]</g:envelope>);

        set-variable("fnRef", .);
        set-variable("firstChildP", true());
        for-each $fn/node() {
            set-variable("child", .);
            delete();

            if $child/self::html:p {
                set-element-name("html:span", $child);

                set-variable("childClasses", get-class("", $child));
                if $childClasses {
                    set-attribute("class", $childClasses, $child);
                }

                if $firstChildP {
                    set-variable("firstChildP", false());
                } else {
                    insert-before(<br/>, $fnRef);
                }
            }

            insert-before($child, $fnRef);
        }

        insert-before(<g:envelope>[/footnote]</g:envelope>);

        delete();
    }
}

for-each /html/body//div[get-class("^role-((foot)|(end))notes$")] {
    delete();
}
-pu edit.after.footnotes "inline_footnotes.xed"
-p epub.split-before-level 0
-p epub.use-id-as-filename no
-p epub.identifier ""
-o epub1_1
--
XMLmind Word To XML Support List
[email protected]
http://www.xmlmind.com/mailman/listinfo/w2x-support

Reply via email to