Hello!
I�m using xslt to create a text document with data from a xml-structure.
I�m using xsl:for-each to loop throw the xml. But I have problem to know is the previous tag have the same value as the current tag. Trying to solve this with recursive calls but it fails. The recursive call seems not to be called because it is inside a for-each loop.
My thought with the recursive call was that the current value should be compared with the next tags value.
The purpose of everything is that I will only write the header if the tag LAN has a new value.
xslt:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:java="http://xml.apache.org/xslt/java"
xmlns:text="http://www.ora.com/XSLTCookBook/namespaces/text"/>
<xsl

utput method="text"/>
<xsl:template name="root" match="/">
<xsl:call-template name="main">
<xsl:with-param name="lan" select="'0'"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="main">
<xsl

aram name="lan"/>
<xsl:for-each select="ROWSET/ROW">
<!--This if-statement is not working because the lan parameter is always 0. (never changing value) -->
<xsl:if test="number(LAN) != number($lan)">
<xsl:call-template name="performLanHeader">
<xsl:with-param name="lan" select="LAN"/>
</xsl:call-template>
</xsl:if>
<xsl:call-template name="performrow">
</xsl:call-template>
<!--recursive call to template main, is never called, WHY?? -->
<xsl:call-template name="main">
<xsl:with-param name="lan" select="LAN"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="performLanHeader">
<xsl

aram name="lan"/>
Department: <xsl:value-of select="$lan"/>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template name="performrow">
<xsl:value-of select="RUBRIK1"/>
<xsl:value-of select="K1"/>
<xsl:value-of select="K2"/>
<xsl:value-of select="K3"/>
<xsl:value-of select="K4"/>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
Xml:
<?xml version="1.0" encoding="UTF-8"?>
<ROWSET>
<ROW num="1">
<LAN>01</LAN>
<RUBRIK1>OPPENVARD</RUBRIK1>
<RUBRIK2>EGENVARD</RUBRIK2>
<K1>123456789</K1>
<K2>0</K2>
<K3>898.5</K3>
<K4>9</K4>
</ROW>
<ROW num="2">
<LAN>01</LAN>
<RUBRIK1>OPPENVARD</RUBRIK1>
<RUBRIK2>HJALPMEDEL</RUBRIK2>
<K1>1893.5</K1>
<K2>5</K2>
<K3>2901</K3>
<K4>6</K4>
</ROW>
<ROW num="3">
<LAN>05</LAN>
<RUBRIK1>OPPENVARD</RUBRIK1>
<RUBRIK2>HJALPMEDEL</RUBRIK2>
<K1>1893.5</K1>
<K2>5</K2>
<K3>1893.5</K3>
<K4>5</K4>
</ROW>
<ROW num="4">
<LAN>06</LAN>
<RUBRIK1>OPPENVARD</RUBRIK1>
<RUBRIK2>KREDITERING</RUBRIK2>
<K1>0</K1>
<K2>0</K2>
<K3>360</K3>
<K4>3</K4>
</ROW>
</ROWSET>
This is my wished print result:
Department: 01
OPPENVARD 123456789 0 898.5 9
OPPENVARD 1893.5 5 2901 6
Department: 05
OPPENVARD 1893.5 5 1893.5 5
Department: 06
OPPENVARD 0 0 360 3
Thanks for any help.
Regards
Mats