这是我的代码:
<xsl:choose>
<xsl:when test="$all_alerts[(g:line_abbr = 'MFL') or (g:line_abbr = 'BSL') or (g:line_abbr = 'CCT') or (g:line_abbr = 'NHSL') and (g:problem != 'normal_service')]">
<b>Subway</b><br /><br />
<xsl:for-each select="$all_alerts[g:line_abbr = 'MFL']">
<xsl:if test="g:problem != 'normal_service'"><xsl:value-of select="g:line"/> | <a href="/m/alert/mfl.html">
<xsl:if test="g:problem = 'station_advisory'">Station Advisory</xsl:if>
<xsl:if test="g:problem = 'stop_advisory'">Stop Advisory</xsl:if>
<xsl:if test="g:problem = 'customer_notice'">Customer Notice</xsl:if>
<xsl:if test="g:problem = 'service_advisory'">Service Advisory</xsl:if>
<xsl:if test="g:problem = 'shuttle_bus'">Shuttle Bus</xsl:if></a><br /><br /></xsl:if>
<xsl:if test="g:problem = 'normal_service'"></xsl:if>
</xsl:for-each>
<xsl:for-each select="$all_alerts[g:line_abbr = 'BSL']">
<xsl:if test="g:problem != 'normal_service'"><xsl:value-of select="g:line"/> | <a href="/m/alert/bsl.html">
<xsl:if test="g:problem = 'station_advisory'">Station Advisory</xsl:if>
<xsl:if test="g:problem = 'stop_advisory'">Stop Advisory</xsl:if>
<xsl:if test="g:problem = 'customer_notice'">Customer Notice</xsl:if>
<xsl:if test="g:problem = 'service_advisory'">Service Advisory</xsl:if>
<xsl:if test="g:problem = 'shuttle_bus'">Shuttle Bus</xsl:if></a><br /><br /></xsl:if>
<xsl:if test="g:problem = 'normal_service'"></xsl:if>
</xsl:for-each>
<xsl:for-each select="$all_alerts[g:line_abbr = 'CCT']">
<xsl:if test="g:problem != 'normal_service'"><xsl:value-of select="g:line"/> | <a href="/m/alert/cct.html">
<xsl:if test="g:problem = 'station_advisory'">Station Advisory</xsl:if>
<xsl:if test="g:problem = 'stop_advisory'">Stop Advisory</xsl:if>
<xsl:if test="g:problem = 'customer_notice'">Customer Notice</xsl:if>
<xsl:if test="g:problem = 'service_advisory'">Service Advisory</xsl:if>
<xsl:if test="g:problem = 'shuttle_bus'">Shuttle Bus</xsl:if></a><br /><br /></xsl:if>
<xsl:if test="g:problem = 'normal_service'"></xsl:if>
</xsl:for-each>
<xsl:for-each select="$all_alerts[g:line_abbr = 'NHSL']">
<xsl:if test="g:problem != 'normal_service'"><xsl:value-of select="g:line"/> | <a href="/m/alert/nhsl.html">
<xsl:if test="g:problem = 'station_advisory'">Station Advisory</xsl:if>
<xsl:if test="g:problem = 'stop_advisory'">Stop Advisory</xsl:if>
<xsl:if test="g:problem = 'customer_notice'">Customer Notice</xsl:if>
<xsl:if test="g:problem = 'service_advisory'">Service Advisory</xsl:if>
<xsl:if test="g:problem = 'shuttle_bus'">Shuttle Bus</xsl:if></a><br /><br /></xsl:if>
<xsl:if test="g:problem = 'normal_service'"></xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
如果g:line_abbr
有g:problem != 'normal service'
,那么我想要显示标题“地铁”以及以下信息,否则我甚至不希望显示任何地方甚至是地铁的标题。
当for-eachs
全部为空白时,以下内容不会隐藏标题“地铁”。
答案 0 :(得分:2)
我明白了。
对于那些感兴趣的人来说,是让它发挥作用的部分。
您必须将其粘贴到xsl:when
声明
<xsl:when test="$all_alerts[((g:line_abbr = 'MFL') and (g:problem != 'normal_service')) or ((g:line_abbr = 'BSL') and (g:problem != 'normal_service')) or
((g:line_abbr = 'CCT') and (g:problem != 'normal_service')) or ((g:line_abbr = 'NHSL') and (g:problem != 'normal_service'))]">
答案 1 :(得分:1)
难道你不认为这是更好的逻辑吗?
<xsl:variable name="$test_alerts" select="$all_alerts[contains('|MFL|BSL|CCT|NHSL|',concat('|',g:line_abbr,'|')]"/>
<xsl:if test="$test_alerts">
<b>Subway</b><br /><br />
<xsl:for-each select="$test_alerts">
<xsl:sort select="g:line_abbr">
<xsl:if test="g:problem != 'normal_service'">
<xsl:value-of select="concat(g:line,' | ')"/>
<a href="/m/alert/{translate(g:line_abbr,'MFLBSCTNH','mflbsctnh')}.html">
<xsl:call-template name="capitalize">
<xsl:with-param name="string" select="g:problem"/>
<xsl:call-template>
</xsl:if>
</xsl:for-each>
</xsl:if>
............................................
<xsl:template name="capitalize">
<xsl:param name="string"/>
<xsl:param name="norm-string" select="concat($string,'_')"/>
<xsl:if test="$norm-string != ''">
<xsl:value-of select="concat(translate(substring($norm-string,1,1),
'qwertyuiopasdfghjklzxcvbnm',
'QWERTYUIOPASDFGHJKLZXCVBNM'),
substring(substring-before($norm-string,'_'),2),
' ')"/>
<xsl:call-template name="capitalize">
<xsl:with-param name="norm-string"
select="substring-after($norm-string,'_')"/>
<xsl:call-template>
</xsl:if>
</xsl:template>