【发布时间】:2017-11-14 09:01:29
【问题描述】:
我有一些结构如下的 XML 文件:
<titles>
<title mode="example" name="name_example">
<titleselect>
<attribute_a>attrib_a</attribute_a>
<attribute_b>attrib_b</attribute_b>
<attribute_c>attrib_c</attribute_c>
<sort_attribute>New York</sort_attribute>
</titleselect>
</title>
<title mode="another_example" name="another_name">
<titleselect>
<attribute_a>attrib_a</attribute_a>
<attribute_b>attrib_b</attribute_b>
<attribute_c>attrib_c</attribute_c>
<sort_attribute>Boston</sort_attribute>
</titleselect>
</title>
<title mode="final_example" name="final_name">
<titleselect>
<attribute_a>attrib_a</attribute_a>
<attribute_b>attrib_b</attribute_b>
<attribute_c>attrib_c</attribute_c>
<sort_attribute>Chicago</sort_attribute>
</titleselect>
</title>
</titles>
我正在尝试按“sort_attribute”的字母顺序对“标题”进行排序。我想要的输出是这样的:
<titles>
<title mode="another_example" name="another_name">
<titleselect>
<attribute_a>attrib_a</attribute_a>
<attribute_b>attrib_b</attribute_b>
<attribute_c>attrib_c</attribute_c>
<sort_attribute>Boston</sort_attribute>
</titleselect>
</title>
<title mode="final_example" name="final_name">
<titleselect>
<attribute_a>attrib_a</attribute_a>
<attribute_b>attrib_b</attribute_b>
<attribute_c>attrib_c</attribute_c>
<sort_attribute>Chicago</sort_attribute>
</titleselect>
</title>
<title mode="example" name="name_example">
<titleselect>
<attribute_a>attrib_a</attribute_a>
<attribute_b>attrib_b</attribute_b>
<attribute_c>attrib_c</attribute_c>
<sort_attribute>New York</sort_attribute>
</titleselect>
</title>
</titles>
有没有办法实现这一点,最好使用 XSLT 或 Python? 我对 XSLT 的世界完全陌生,但我尝试过应用来自其他相关问题的一些解决方案,例如XSLT sort parent element based on child element attribute 无济于事。
【问题讨论】:
-
是的,这很简单。您链接到的答案已经很好了,您尝试应用它的目的是什么?