我需要输出具有正确序列号的附属节点(仅且仅具有“空”子节点的节点)(请参阅 XML)
下面的 XML 中没有属性,只有元素和值。
<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>
排序:我需要计算每个位置的每个所属子节点(例如房屋、附属建筑、车辆) 注意,带有 houseWithAC 子节点的房屋算作两个节点! 序列格式为 Loc ### / Item ###
我需要用正确的序列号输出每个有空子的附属节点(见上文)
另请注意:“集合”节点如位置、属性有许多子节点,而节点所有物 - 只有一个。
我试图创建一个递归循环,但 id 不起作用:如果我有没有“空”子的附属节点,我仍然会进入 if 语句(看起来那个条件总是正确的)
像这样的东西:。. . . . . . . . . .
<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>