2017-12-14 21 views
0

오늘부터 2 년이 넘은 모든 행을 굵게 표시해야합니다.
코드를 복제하지 않고 어떻게합니까?
조건을 알아낼 수는 있지만 굵은 체의 다른 스타일로 모든 코드를 복제하지 않는 방법을 알아낼 수는 없습니다. 당신은 그럴 필요 또는 TD의 스타일을 추가하여 굵은처럼조건부 행 스타일 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

것 같습니다 :

여기 내 코드입니다. if 조건 내에서 attribute 함수를 사용하기 만하면됩니다.

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