Skip to content

Commit

Permalink
Now transform works with --lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
weetmuts committed Feb 9, 2025
1 parent 561cb57 commit 651a91e
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/main/c/xmq-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,16 @@ void free_cli_command(XMQCliCommand *cmd)
hashmap_free_and_values(cmd->xslt_params, free);
cmd->xslt_params = NULL;
}
if (cmd->xslt)
{
xsltFreeStylesheet(cmd->xslt);
// The xslt free has freed the internal implementation doc as well.
// Mark it as null to prevent double free.
xmqSetImplementationDoc(cmd->xslt_doq, NULL);
xmqFreeDoc(cmd->xslt_doq);
cmd->xslt = NULL;
}

free(cmd);
}

Expand Down Expand Up @@ -2130,13 +2140,6 @@ bool cmd_transform(XMQCliCommand *command)
xmlFreeDoc(doc);
xmqSetImplementationDoc(command->env->doc, new_doc);

xsltFreeStylesheet(command->xslt);
// The xslt free has freed the internal implementation doc as well.
// Mark it as null to prevent double free.
xmqSetImplementationDoc(command->xslt_doq, NULL);
xmqFreeDoc(command->xslt_doq);
command->xslt = NULL;

return true;
}

Expand Down
29 changes: 29 additions & 0 deletions tests/xslt_010_xmllines.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><fixture start_time="1738166400000" event_id="23" timestamp="1737369994942"/>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><fixture start_time="1738065600000" event_id="7777" timestamp="1737369994951"/>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><fixture start_time="1738164600000" event_id="1234" timestamp="1737369994960"/>
XSLT
xsl:stylesheet(version = 1.0
xmlns:xsl = http://www.w3.org/1999/XSL/Transform)
{
xsl:template(match = /)
{
xsl:variable(name = start
select = /fixture/@start_time)
xsl:variable(name = stamp
select = /fixture/@timestamp)
xsl:variable(name = diff
select = '$start - $stamp')
diff {
xsl:value-of(select = $diff)
','
xsl:value-of(select = /fixture/@event_id)
}
}
}
EXPECTED
diff = 796405058,23
diff = 695605049,7777
diff = 794605040,1234
END
ARGS --lines
29 changes: 29 additions & 0 deletions tests/xslt_011_jsonlines.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
XML
{"name": "Gilbert", "session": "2013", "score": 24, "completed": true}
{"name": "Alexa", "session": "2013", "score": 29, "completed": true}
{"name": "May", "session": "2012B", "score": 14, "completed": false}
{"name": "Deloise", "session": "2012A", "score": 19, "completed": true}
XSLT
xsl:stylesheet(version = 1.0
xmlns:xsl = http://www.w3.org/1999/XSL/Transform)
{
xsl:template(match = /)
{
xsl:variable(name = name
select = /_/name)
xsl:variable(name = score
select = /_/score)
grade {
xsl:value-of(select = $name)
'='
xsl:value-of(select = $score)
}
}
}
EXPECTED
grade = Gilbert=24
grade = Alexa=29
grade = May=14
grade = Deloise=19
END
ARGS --lines
29 changes: 29 additions & 0 deletions tests/xslt_012_xmqlines.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
XML
student{name=Gilbert session=2013 score=24 completed=true}
student{name=Alexa session=2013 score=29 completed=true}
student{name=May session=2012B score=14 completed=false}
student{name=Deloise session=2012A score=19 completed=true}
XSLT
xsl:stylesheet(version = 1.0
xmlns:xsl = http://www.w3.org/1999/XSL/Transform)
{
xsl:template(match = /)
{
xsl:variable(name = name
select = /student/name)
xsl:variable(name = score
select = /student/score)
grade {
xsl:value-of(select = $name)
'='
xsl:value-of(select = $score)
}
}
}
EXPECTED
grade = Gilbert=24
grade = Alexa=29
grade = May=14
grade = Deloise=19
END
ARGS --lines
29 changes: 29 additions & 0 deletions tests/xslt_013_xmllines.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
XML
<fixture start_time="1738166400000" event_id="23" timestamp="1737369994942"/>
<fixture start_time="1738065600000" event_id="7777" timestamp="1737369994951"/>
<fixture start_time="1738164600000" event_id="1234" timestamp="1737369994960"/>
XSLT
xsl:stylesheet(version = 1.0
xmlns:xsl = http://www.w3.org/1999/XSL/Transform)
{
xsl:template(match = /)
{
xsl:variable(name = start
select = /fixture/@start_time)
xsl:variable(name = stamp
select = /fixture/@timestamp)
xsl:variable(name = diff
select = '$start - $stamp')
diff {
xsl:value-of(select = $diff)
','
xsl:value-of(select = /fixture/@event_id)
}
}
}
EXPECTED
diff = 796405058,23
diff = 695605049,7777
diff = 794605040,1234
END
ARGS --lines

0 comments on commit 651a91e

Please sign in to comment.