I am working on xsl to convert mindmap files to csv tree structure. I am using python lxml
There are few questions left - how to omit the root tags needed in the template? Leave them in the results:
AssertionError: ElementTree not initialized, missing root
Source 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>
Output. Pay attention to p tags. How to reset them?
<p>,"Familie" "Familie","Kinder" "Familie","Kinder","Sohn" "Familie","Kinder","Tochter" "Familie","Kinder","Tochter","Hobbies" "Familie","Kinder","Tochter","Hobbies","Fußball" </p>
my sheet
<?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,',"',$nodetext,'"')"/> </xsl:apply-templates> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
source share