cceh / sanskrit-web

An HTML frontend to Sanskrit dictionaries modelled in TEI.
ISC License
1 stars 2 forks source link

XML variables are passed to XSLT without namespaces #36

Open gioele opened 9 years ago

gioele commented 9 years ago

When the XSLT-view code compiles the source XML to be passed to the XSLT engine, it embeds the eventual XML nodes presents in values without all the needed XML namespaces.

For example, the following node

<choice xml:id="abbr-cf_">
    <abbr>cf.</abbr>
    <expan>confer, compare</expan>
</choice>

cannot be embedded as it is because it lacks the necessary TEI namespace.

This bug is a combination of various factors, first of all to a bug in nokogiri where it does not copy over all the needed namespaces: sparklemotion/nokogiri#1200. A question on how to work around this problem has been filed on StackOverflow: Serialize XML node as document with correct namespaces.

gioele commented 9 years ago

An answer to sparklemotion/nokogiri#1200 suggests using doc << v.clone instead of doc << v in the part of the XML serializator that deals with XML nodes.

                        if v.respond_to?(:to_xml)
                                begin
-                                       doc << v.to_xml(:skip_instruct => true).to_s
+                                       doc << v.clone.to_xml(:skip_instruct => true).to_s
                                rescue ArgumentError
                                        # Some to_xml methods don't understand skip_instruct
-                                       doc << v.to_xml.to_s
+                                       doc << v.clone.to_xml.to_s
                                end
                        elsif v.respond_to?(:to_s)