I have an xml document Code: <INDI>@I14@ <NAME>Charlie Accented /ANSEL/</NAME> <SEX>M</SEX> <BIRT> <DATE>15 JUN 1900</DATE> </BIRT> <DEAT> <DATE>5 JUL 1974</DATE> </DEAT> <FAMS>@F6@</FAMS> <FAMC>@F7@</FAMC> <NOTE>@N24@</NOTE> <CHAN> <DATE>11 Jan 2001 <TIME>16:00:06</TIME> </DATE> </CHAN> <RIN>1</RIN> </INDI> that I need to change into a plan text formatted like this it needs the new lines and the leading numbers correspond to the death of each node Code: 0 @I14@ INDI 1 NAME Charlie Accented /ANSEL/ 1 SEX M 1 BIRT 2 DATE 15 JUN 1900 1 DEAT 2 DATE 5 JUL 1974 1 FAMS @F6@ 1 FAMC @F7@ 1 NOTE @N24@ 1 CHAN 2 DATE 11 Jan 2001 3 TIME 16:00:06 1 RIN 1 I'm new to xslt and all I can find when researching it is stuff on xml to html etc I have already coded a program in c# that does this but I would like it done in xslt so I and other people can add more file formats latter
Here you go. Notes: 1. The "<wibble>" and "<br>" elements are merely placeholders 2. As count function is 1 based, subtract one for your zero base 3. self::* ensures that the selected node is an element. 4. If you need a line break, change the <br>. Code: <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method='xml' omit-xml-declaration='yes' /> <xsl:template match="/"> <wibble> <xsl:apply-templates /> </wibble> </xsl:template> <xsl:template match="node()"> <xsl:if test="self::*"> <xsl:call-template name="node_depth" /> <xsl:text> </xsl:text> <xsl:value-of select="name()"/> <xsl:text> </xsl:text> <xsl:value-of select="text()"/> <br/> </xsl:if> <xsl:apply-templates /> </xsl:template> <xsl:template name="node_depth" > <xsl:value-of select="count(ancestor::node()) - 1" /> </xsl:template> </xsl:stylesheet>
well it is going at 10KB a second I'm thinking this could be a problem with mono at this speed anyway here are my two files GEDCOM_5_5.xsl test2.xml 685KB plus the xml files can get larger then 100MB so I need speed