michal-h21 / LuaXML

Fork of LuaXML (originally Paul Chakravarti)
14 stars 9 forks source link

Attribute selector with "xml:lang" does not work #3

Closed zepinglee closed 2 years ago

zepinglee commented 3 years ago

In v1.0o, the attribute selector with "xml:lang" always returns an empty table. An example is as follows.

kpse.set_program_name("luatex")

local dom = require("luaxml-domobject")

local document = [[
<style xmlns="http://purl.org/net/xbiblio/csl" class="note" version="1.0">
  <locale xml:lang="en-US">
  </locale>
  <locale xml:lang="zh-CN">
  </locale>
</style>
]]

local obj = dom.parse(document)

for i, locale in ipairs(obj:query_selector("locale[xml:lang=\"en-US\"]")) do
    print(i, locale:get_element_name(), locale:get_attribute("xml:lang"))
end

This is mainly because the colon is not included in the attr_name pattern.

https://github.com/michal-h21/LuaXML/blob/30b13e41b0e2450a5e99ca908589fb07f0419266/luaxml-parse-query.lua#L24

Some comments in the code say that luaxml doesn't support XML namespaces and elements must be queried with "namespace|element". But the "|" only works with tag name not attribute name.

michal-h21 commented 3 years ago

Thanks for the report. I've hopefully fixed this issue in the development version of LuaXML.

michal-h21 commented 2 years ago

I've posted the fix to CTAN, so it should be available in TL soon.