python – xslt模板根标签,在文本输出中省略
发布时间:2020-12-20 13:31:26 所属栏目:Python 来源:网络整理
导读:我在xsl上工作,将思维导图文件转换为csv树结构.我使用 python lxml 还有一个问题 – 如何省略模板中必需的根标签?将它们留下结果: AssertionError: ElementTree not initialized,missing root 源码xml map version="0.9.0"node TEXT="Familie"node TEXT="K
我在xsl上工作,将思维导图文件转换为csv树结构.我使用
python lxml
还有一个问题 – 如何省略模板中必需的根标签?将它们留下结果: AssertionError: ElementTree not initialized,missing root 源码xml <map version="0.9.0"> <node TEXT="Familie"> <node TEXT="Kinder"> <node TEXT="Sohn"> </node> <node TEXT="Tochter"> <node TEXT="Hobbies"> <node TEXT="Fußball"> </node> </node> </node> </node> </node> </map> 输出.注意p标签.怎么放他们? <p>,"Familie" "Familie","Kinder" "Familie","Kinder","Sohn" "Familie","Tochter" "Familie","Tochter","Hobbies" "Familie","Hobbies","Fußball" </p> 我的表 <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" indent="no" encoding="ISO-8859-1" omit-xml-declaration="yes" media-type="string"/> <xsl:strip-space elements="*" /> <xsl:template match="/"> <p> <xsl:apply-templates/> </p> </xsl:template> <xsl:template match="node"> <xsl:param name="par"/> <xsl:variable name="nodetext" select="@TEXT"/> <xsl:variable name="depth" select="count(ancestor::*)"/> <xsl:value-of select="$par"/>,"<xsl:value-of select="$nodetext"/>" <xsl:choose> <xsl:when test="$depth<2"> <xsl:apply-templates> <xsl:with-param name="par" select="concat('"',$nodetext,'"')"/> </xsl:apply-templates> </xsl:when> <xsl:otherwise> <xsl:apply-templates> <xsl:with-param name="par" select="concat($par,',"','"')"/> </xsl:apply-templates> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> 解决方法
更改此模板:
<xsl:template match="/"> <p> <xsl:apply-templates/> </p> </xsl:template> ……对此: <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |