2017-12-14 20 views
0

今日から2歳以上のすべての行を太字で表示する必要があります。
コードを複製せずにどうすればいいですか?
私は条件を理解することができますが、ボールドのために別のスタイルですべてのコードを複製しないでください。ここで条件付き行スタイルxslと重複コードの回避

は私のコードです:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:key name="albums-by-country" match="Album" use="Country" /> 
<xsl:template match="Albums"> 
<html> 
<head> 
<style> 
h4 { 
    text-decoration: underline; 
    font-weight: bold; 

} 
</style> 
</head> 
    <body> 
    <xsl:for-each select="Album[count(. | key('albums-by-country', Country)[1]) = 1]"> 
     <xsl:sort select="Country" /> 
     <h4 style="color:green;"><xsl:value-of select="Country" style="color:red;" /><br /></h4> 


        <table border="1"> 
    <tr bgcolor="#979994"> 
     <th style="text-align:left">Price</th> 
     <th style="text-align:left">Link</th> 
     <th style="text-align:left">Company</th> 
     <th style="text-align:left">Name</th> 
     <th style="text-align:left">Date</th> 
     <th style="text-align:left">Artist</th> 
    </tr> 
    <xsl:for-each select="key('albums-by-country', Country)"> 
<xsl:sort select="Date" /> 
    <tr> 
     <td><xsl:value-of select="Price"/></td> 
     <td><xsl:value-of select="Link"/></td> 
     <td><xsl:value-of select="Company"/></td> 
     <td><xsl:value-of select="Name"/></td> 

    <xsl:choose> 
     <xsl:when test="string-length(Date)>4"> 
     <td><xsl:value-of select="concat(substring(Date,5,2),'/',substring(Date,7,8),'/',substring(Date,1,4))"/></td> 
</xsl:when> 
<xsl:otherwise> 
<td><xsl:value-of select="concat('01/01/',substring(Date,1,4))"/></td> 
</xsl:otherwise> 
</xsl:choose> 
     <td style="color:red;"><xsl:value-of select="Artist"/></td> 
    </tr> 
    </xsl:for-each> 
     <tr> 
       <td colspan="2">Total Amount</td> 
       <td bgcolor="#ffff00"><xsl:value-of select="sum(key('albums-by-country', Country)/Price)"/></td> 
      </tr> 
    </table> 
    <html> 
    <body> 
</xsl:template>  
</xsl:stylesheet> 

答えて

0

あなたがTRかTDのにスタイルを追加することにより、太字ているように見えます。条件関数内で属性関数を使用するだけです。

<tr> <!-- or td --> 
    <xsl:if test="{Older the 2 years}"> 
     <xsl:attribute name="style">bold whatever</attribute> 
    </if> 
関連する問題