Python (并非如此)子节点到列表的高级xsl转换
输入: 理想产出:Python (并非如此)子节点到列表的高级xsl转换,python,xml,xslt,xpath,lxml,Python,Xml,Xslt,Xpath,Lxml,输入: 理想产出: <root> <aa><aaa/><bbb/><ccc/><ddd/><eee/></aa> <bb><ggg/></bb> </root> 我提出了简单的xslt,但它只正确地处理标记,而不创建标记列表 XSLT: 输出: <xsl:stylesheet version="1.0" xmlns:xsl="ht
<root>
<aa><aaa/><bbb/><ccc/><ddd/><eee/></aa>
<bb><ggg/></bb>
</root>
我提出了简单的xslt,但它只正确地处理标记,而不创建标记列表
XSLT:
输出:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- select all elements that doesn't have any child nodes (elements or text etc) -->
<xsl:template match="//*[not(node())]">
<xsl:value-of select="name()"/>
</xsl:template>
</xsl:stylesheet>
另外,它是python脚本的一部分。在python脚本中使用xslt进行这样的转换会有帮助吗?或者使用简单xpath和python逻辑的python解决方案会更好吗?一个示例不能代替解释所需转换背后的逻辑。我可以想出几种不同的方法来处理示例输入并获得相同的输出 以下是您想要完成的猜测阅读评论: XSLT1.0
示例不能代替解释所需转换背后的逻辑。我可以想出几种不同的方法来处理示例输入并获得相同的输出 以下是您想要完成的猜测阅读评论: XSLT1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- select all elements that doesn't have any child nodes (elements or text etc) -->
<xsl:template match="//*[not(node())]">
<xsl:value-of select="name()"/>
</xsl:template>
</xsl:stylesheet>
<root>
<aa>aaabbbcccdddeee</aa>
<bb>ggg</bb>
</root>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<root>
<!-- select all elements that don't have any child nodes -->
<xsl:for-each select="//*[not(node())]">
<!-- create an element with the name of the parent element -->
<xsl:element name="{name(..)}">
<xsl:value-of select="name()"/>
</xsl:element>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>