Hi all,
I have the following xml-document.
Code:
<?xml version="1.0" ?>
<datarows>
<datarow class="a">Line 0</datarow>
<datarow class="b">Subline 0</datarow>
<datarow class="b">Subline 1</datarow>
<datarow class="b">Subline 2</datarow>
<datarow class="a">Line 1</datarow>
<datarow class="b">Subline 10</datarow>
<datarow class="b">Subline 11</datarow>
<datarow class="b">Subline 12</datarow>
</datarows>
And i want to end up with a textfile like:
"Line0";"Subline 0";"Subline 1";"Subline 2"
"Line1";"Subline 10";"Subline 11";"Subline 12"
I have made the following stylesheet.
Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="utf-8" />
<xsl:strip-space elements="*"/>
<xsl:template match="datarows[datarow[@class='b']]">
<xsl:apply-templates select="preceding-sibling::datarows[datarow[@class='a']]" />
<xsl:apply-templates select="datarow" />
</xsl:template>
<xsl:template match="datarow">
<xsl:text>"</xsl:text>
<xsl:value-of select="normalize-space(.)" />
<xsl:choose>
<xsl:when test="position() = last()">
<xsl:text>"#13;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>";</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
First, I can't figure out how to get two lines in the outputdocument.
Second, i want to ask you if there is a way 'to speed up the stylesheet'.
When i have a document that is 10Mb, the time to transform the document can be very long.
The main issue here is, that time the parser encounters a datarow-element with class 'b' it has to search back in the tree to find the previous datarow-element 'a'.
If you have a very big document, you can imagine what happens.
Is it a good idea to work with a xsl:variable or maybe someone has a different approach?
Thanks in advance, Raoul.