1- from style_variant_builder .prune import NS , CSLPruner
1+ from style_variant_builder .prune import CSLPruner , _tag
22
33EXAMPLE_XML = """<?xml version="1.0"?>
44<style xmlns="http://purl.org/net/xbiblio/csl">
1212</style>
1313"""
1414
15+ EXAMPLE_WITH_XML_MODEL = """<?xml version="1.0"?>
16+ <?xml-model href="http://example.com/schema.rng" type="application/xml"?>
17+ <style xmlns="http://purl.org/net/xbiblio/csl">
18+ <macro name="test-macro"><text value="test"/></macro>
19+ <citation>
20+ <layout>
21+ <text macro="test-macro"/>
22+ </layout>
23+ </citation>
24+ </style>
25+ """
26+
1527
1628def test_prune_removes_unused_macros (tmp_path ):
1729 xml_path = tmp_path / "test.csl"
@@ -22,7 +34,7 @@ def test_prune_removes_unused_macros(tmp_path):
2234 pruner .build_used_macros ()
2335 pruner .prune_macros ()
2436 assert pruner .root is not None
25- macros = [m .get ("name" ) for m in pruner .root .findall (f" { NS } macro" )]
37+ macros = [m .get ("name" ) for m in pruner .root .findall (_tag ( " macro") )]
2638 assert "used-macro" in macros
2739 assert "unused-macro" not in macros
2840
@@ -36,5 +48,24 @@ def test_prune_keeps_used_macros(tmp_path):
3648 pruner .build_used_macros ()
3749 pruner .prune_macros ()
3850 assert pruner .root is not None
39- macros = [m .get ("name" ) for m in pruner .root .findall (f" { NS } macro" )]
51+ macros = [m .get ("name" ) for m in pruner .root .findall (_tag ( " macro") )]
4052 assert "used-macro" in macros
53+
54+
55+ def test_xml_model_pi_excluded_from_output (tmp_path ):
56+ """Test that xml-model processing instructions are excluded from saved output."""
57+ input_path = tmp_path / "input.csl"
58+ output_path = tmp_path / "output.csl"
59+ input_path .write_text (EXAMPLE_WITH_XML_MODEL )
60+
61+ pruner = CSLPruner (input_path , output_path )
62+ pruner .parse_xml ()
63+ pruner .prune_macros ()
64+ pruner .save ()
65+
66+ output_content = output_path .read_text ()
67+ # Verify xml-model PI is not in output
68+ assert "<?xml-model" not in output_content
69+ # Verify the actual content is preserved
70+ assert "<macro" in output_content
71+ assert "<citation>" in output_content
0 commit comments