I need to output outbuilding nodes (only and only the ones that have a 'vacant'-child) with correct sequence number (see XML)
There are no attributes in XML below, just elements and values.
<stuff>
<locations>
<location>
<properties>
<property>
<belongings>
<house>
<houseWithAC/>
</house>
</belongings>
</property>
<property>
<belongings>
<outbuilding/>
</belongings>
</property>
<property>
<belongings>
<outbuilding>
<vacant/>
</outbuilding>
</belongings>
</property>
<property>
<belongings>
<outbuilding>
<vacant/>
</outbuilding>
</belongings>
</property>
<property>
<belongings>
<vehicle/>
</belongings>
</property>
</properties>
</location>
<location>
<properties>
<property>
<belongings>
<vehicle/>
</belongings>
</property>
<property>
<belongings>
<outbuilding/>
</belongings>
</property>
<property>
<belongings>
<house/>
</belongings>
</property>
<property>
<belongings>
<outbuilding>
<vacant/>
</outbuilding>
</belongings>
</property>
<property>
<belongings>
<barn/>
</belongings>
</property>
</properties>
</location>
</locations>
</stuff>
sequencing: I need to count every belonging child node per location (for ex. house, outbuilding, vehicle) Note, house with houseWithAC child counts as two nodes !! the sequence format is Loc ### / Item ###
I need to output every outbuilding node that has vacant child, with the correct sequence numbers (see above)
Note also: "collection" nodes like locations, properties have many children, while node belongings - only one.
I tried to create a recursive loop, but id does not work: if I have outbuilding node without "vacant"-child I still step into the if statement (looks like that condition is allways true)
Something like this: . . . . . . . . . . .
<xsl:for-each select="Locations/Location">
<xsl:variable name="LOCID">
<xsl:number level="single" count="*" format="001"/>
</xsl:variable>
<xsl:call-template name="WriteItems">
<xsl:with-param name="propertiesNodes" select="properties/property"/>
<xsl:with-param name="NumberOfProperties" select="count(properties/property)"/>
<xsl:with-param name="LocCount" select="$LOCID"/>
</xsl:call-template>
</xsl:for-each>
. . . . . . . . . . . . .
<xsl:template name="WriteItems">
<xsl:param name="propertiesNodes"/>
<xsl:param name="NumberOfProperties"/>
<xsl:param name="LocCount"/>
<xsl:param name="Index">1</xsl:param>
<xsl:param name="ItemCount">1</xsl:param>
<xsl:choose>
<xsl:when test="$Index > $NumberOfProperties"/>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$propertiesNodes[$Index]/belongings/house/houseWithAC">
<xsl:call-template name="WriteItems">
<xsl:with-param name="propertiesNodes" select="$propertiesNodes"/>
<xsl:with-param name="NumberOfProperties" select="$NumberOfProperties"/>
<xsl:with-param name="LocCount" select="$LocCount"/>
<xsl:with-param name="Index" select="$Index + 1"/>
<xsl:with-param name="ItemCount" select="$ItemCount + 2"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$propertiesNodes[$Index]/belongings/house">
<xsl:call-template name="WriteItems">
<xsl:with-param name="propertiesNodes" select="$propertiesNodes"/>
<xsl:with-param name="NumberOfProperties" select="$NumberOfProperties"/>
<xsl:with-param name="LocCount" select="$LocCount"/>
<xsl:with-param name="Index" select="$Index + 1"/>
<xsl:with-param name="ItemCount" select="$ItemCount + 1"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$propertiesNodes[$Index]/belongings/vehicle">
<xsl:call-template name="WriteItems">
<xsl:with-param name="propertiesNodes" select="$propertiesNodes"/>
<xsl:with-param name="NumberOfProperties" select="$NumberOfProperties"/>
<xsl:with-param name="LocCount" select="$LocCount"/>
<xsl:with-param name="Index" select="$Index + 1"/>
<xsl:with-param name="ItemCount" select="$ItemCount + 1"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$propertiesNodes[$Index]/belongings/barn">
<xsl:call-template name="WriteItems">
<xsl:with-param name="propertiesNodes" select="$propertiesNodes"/>
<xsl:with-param name="NumberOfProperties" select="$NumberOfProperties"/>
<xsl:with-param name="LocCount" select="$LocCount"/>
<xsl:with-param name="Index" select="$Index + 1"/>
<xsl:with-param name="ItemCount" select="$ItemCount + 1"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$propertiesNodes[$Index]/belongings/outbuilding">
<xsl:if test="$propertiesNodes[$Index]/belongings/outbuilding/vacant">
<xsl:variable name="ITEMID">
<xsl:value-of select="format-number($ItemCount,'000')"/>
</xsl:variable>
.... output as concat('- ', $LocCount, '/', $ITEMID) ...... some description ....
</xsl:if>
<xsl:call-template name="WriteItems">
<xsl:with-param name="propertiesNodes" select="$propertiesNodes"/>
<xsl:with-param name="NumberOfProperties" select="$NumberOfProperties"/>
<xsl:with-param name="LocCount" select="$LocCount"/>
<xsl:with-param name="Index" select="$Index + 1"/>
<xsl:with-param name="ItemCount" select="$ItemCount + 1"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>