我有以下结构:
<?xml version="1.0" encoding="UTF-8"?>
<Legs>
<Leg>
<LegNo>1</LegNo>
<RaceInfo>
<RaceNo>1</RaceNo>
<Name/>
<BaseDistance>2140</BaseDistance>
<StartMethod Code="A"/>
<StartTime>
<Hour>13</Hour>
<Minute>48</Minute>
</StartTime>
<Status>OpenForSell</Status>
<NumberOfStarts>10</NumberOfStarts>
</RaceInfo>
<Starts>
<Start>
<StartNo>1</StartNo>
<Horse>
<RegNo>578001020080423</RegNo>
<Name>Mino</Name>
</Horse>
<Driver>
<LicenseNo>29749</LicenseNo>
<FirstName>Hovel</FirstName>
<LastName>Helmen</LastName>
</Driver>
<Distance>2140</Distance>
<Scratched>false</Scratched>
<Ranking>2</Ranking>
</Start>
<Start>
<StartNo>2</StartNo>
<Horse>
<RegNo>578001020080121</RegNo>
<Name>Furderud Svarten</Name>
</Horse>
<Driver>
<LicenseNo>4290</LicenseNo>
<FirstName>Bjørn</FirstName>
<LastName>Humborstad</LastName>
</Driver>
<Distance>2140</Distance>
<Scratched>false</Scratched>
<Ranking/>
</Start>
</Starts>
</Leg>
</Legs>
我正在使用以下代码的一部分转换为 XML:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
<p class="txt">
<xsl:text>Rangering: </xsl:text>
<xsl:variable name="found">
<xsl:text>false</xsl:text>
</xsl:variable>
<xsl:for-each select="Legs[@ResultsComplete='true']/Leg">
<xsl:value-of select="LegNo" />
<xsl:text>. avd: </xsl:text>
<xsl:call-template name="getRanking">
<xsl:with-param name="structure" select="Starts" />
<xsl:with-param name="counter" select="1" />
<xsl:with-param name="winner" select="Winners/Winner/@StartNo" />
</xsl:call-template>
<xsl:choose>
<xsl:when test="Starts/Start/Scratched = 'true'">
<xsl:text> (str. </xsl:text>
<xsl:for-each select="Starts/Start[Ranking=0]/StartNo">
<xsl:value-of select="." />
<xsl:choose>
<xsl:when test="position() = last()">
<xsl:text>)</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>, </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="position() = last()">
<xsl:text>.</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>, </xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</p>
<xsl:template name="getRanking">
<xsl:param name="structure"/>
<xsl:param name="counter"/>
<xsl:param name="winner"/>
<xsl:choose>
<xsl:when test="$structure/Start[Ranking=$counter]/StartNo = $winner">
<xsl:value-of select="$structure/Start[Ranking=$counter]/StartNo"/>
<!--<xsl:text> </xsl:text>-->
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$structure/Start[Ranking=$counter]/StartNo"/>
<xsl:text>-</xsl:text>
<xsl:call-template name="getRanking">
<xsl:with-param name="structure" select="$structure"/>
<xsl:with-param name="counter" select="$counter + 1"/>
<xsl:with-param name="winner" select="$winner"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
输出应为以逗号分隔的数字列表。然而。当我点击一个空标签时,我收到一个'FORG0001: Cannot convert string to double'
错误。
我正在使用撒克逊 9.4.0.6。
我试图在选择块之前添加一个 if 语句,但这似乎并不重要。
我想要实现的是跳过具有空 Ranking 元素的块。
这是所需的输出(当我没有空的排名元素时有效:
<p class="txt">Rangering: 1. avd: 7 (str. 2, 6), 2. avd: 5, 3. avd: 1-6, 4. avd: 1-11 (str. 3, 6, 8, 12), 5. avd: 2-12-6 (str. 4, 5, 10).</p>