2010-08-13 98 views
2

這裏是我的代碼:XSLT |選擇/當

<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_abbrg:problem != 'normal service'然後我想要的標題地鐵展示以及以下信息,否則我什麼也不想要顯示在所有甚至標題的地鐵。

for-eachs全部爲空時,以下不隱藏標題'地鐵'。

回答

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

你不覺得這是更好的邏輯?

<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> 
+0

它可能但我沒有時間去通過並取代物流,當我不完全擁有它。但如果我有時間的話。我會試試這個。謝謝! – balexander 2010-08-16 20:04:53

+0

@ Bry4n:沒問題。我只是添加了這個答案,因爲看到你的代碼的人可能認爲XSLT是冗長的,而不是他們的工具。 – 2010-08-16 20:27:20