Fix up some more xml tests and other small bugs

This commit is contained in:
2025-03-26 01:52:48 +01:00
parent e5092edf53
commit 2bfd9f951e
2 changed files with 52 additions and 64 deletions

View File

@@ -59,6 +59,13 @@ func (p *XMLProcessor) ProcessContent(content string, path string, luaExpr strin
}
log.Printf("%#v", result)
modified := false
modified = L.GetGlobal("modified").String() == "true"
if !modified {
log.Printf("No changes made to node at path: %s", node.Data)
continue
}
// Apply modification based on the result
if updatedValue, ok := result.(string); ok {
// If the result is a simple string, update the node value directly
@@ -105,7 +112,7 @@ func (p *XMLProcessor) ToLua(L *lua.LState, data interface{}) error {
for _, attr := range node.Attr {
L.SetField(attrs, attr.Name.Local, lua.LString(attr.Value))
}
L.SetField(table, "attributes", attrs)
L.SetField(table, "attr", attrs)
}
L.SetGlobal("v", table)
@@ -217,7 +224,7 @@ func updateNodeFromMap(node *xmlquery.Node, data map[string]interface{}) {
}
// Update attributes if present
if attrs, ok := data["attributes"].(map[string]interface{}); ok && node.Type == xmlquery.ElementNode {
if attrs, ok := data["attr"].(map[string]interface{}); ok && node.Type == xmlquery.ElementNode {
for name, value := range attrs {
if strValue, ok := value.(string); ok {
// Look for existing attribute