2017-12-14 15 views
0

날짜를 문자열로 가져오고 다음과 같은 형식으로 날짜를 표시해야합니다. MM/DD/YYYY 연도가 1 년인 경우 01/01을 추가해야합니다. 오늘부터 2 년이 넘은 앨범도 굵게 표시해야합니다. 어떻게해야합니까? fuctions를 어떻게 추가합니까? JQUERY 만 사용할 수 있으며 JS는 사용할 수 없습니다. 감사합니다. .xsl에서 jquery 함수를 추가하는 방법 (날짜)

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     xmlns:ms="urn:schemas-microsoft-com:xslt" 
     xmlns:dt="urn:schemas-microsoft-com:datatypes"> 
    <xsl:template match="/"> 
<html> 
<body> 
<style> 
u { 
    text-decoration: underline; 
    font-weight: bold; 
} 
</style> 
    <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="Albums/Album"> 
    <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> 
     <td><xsl:value-of select="Date" /></td> 
     <td style="color:red;"><xsl:value-of select="Artist"/></td> 
    </tr> 
    </xsl:for-each> 
    </table> 
</body> 
</html> 
</xsl:template> 
</xsl:stylesheet> 

와 XML :

는 XSLT에서 자바 스크립트 함수를 호출 할 수 있습니다 동안
<?xml version="1.0" encoding="ISO8859-1"?> 
<?xml-stylesheet type="text/xsl" href="Albums1.xs"?> 
<Albums> 
    <Album> 
     <Name>Empire Burlesque</Name> 
     <Artist>Bob Dylan</Artist> 
     <Country>USA</Country> 
     <Company>Columbia</Company> 
     <Date>19880610</Date> 
    </Album> 
    <Album> 
     <Name>Hide your heart</Name> 
     <Artist>Bonnie Tylor</Artist> 
     <Country>UK</Country> 
     <Company>CBS Records</Company> 
     <Price>9.90</Price> 
     <Date>19880509</Date> 
    </Album> 
    <Album> 
     <Name>Greatest Hits</Name> 
     <Artist>Dolly Parton</Artist> 
     <Country>USA</Country> 
     <Company>RCA</Company> 
     <Price>9.90</Price> 
     <Date>1982</Date> 
    </Album> 
    <Album> 
     <Name>Still got the blues</Name> 
     <Artist>Gary More</Artist> 
     <Country>UK</Country> 
     <Company>Virgin redords</Company> 
     <Price>10.20</Price> 
     <Date>1990</Date> 
    </Album> 
    <Album> 
     <Name>Eros</Name> 
     <Artist>Eros Ramazzotti</Artist> 
     <Country>EU</Country> 
     <Company>BMG</Company> 
     <Price>9.90</Price> 
     <Date>1997</Date> 
    </Album> 
    <Album> 
     <Name>25</Name> 
     <Artist>Adele</Artist> 
     <Country>UK</Country> 
     <Company>XL Recordings</Company> 
     <Price>9.90</Price> 
     <Date>20151120</Date> 
    </Album> 
    <Album> 
     <Name>1000 Forms of Fear</Name> 
     <Artist>Sia</Artist> 
     <Country>USA</Country> 
     <Company>RCA Records</Company> 
     <Price>9.90</Price> 
     <Date>20140704</Date> 
    </Album> 
    <Album> 
     <Name>Rattle and Hum</Name> 
     <Artist>U2</Artist> 
     <Country>EU</Country> 
     <Company>Island</Company> 
     <Price>9.90</Price> 
     <Date>19881010</Date> 
    </Album> 
</Albums> 
+1

jQuery를 *이 * JS입니다. – charlietfl

+0

나는 아무 계획도없이 그것을하도록 요구 받았다. jQuery를 사용하려면 – user4485863

+0

자바 스크립트를 전혀 사용하지 않고 순수하게 XSLT에서도이 작업을 수행 할 수 있습니다. 정말 jquery를 사용해야합니까? –

답변

0

, 그것은 매우 프로세서가 의존

여기 내 XSL입니다. 그러나, 당신은 자바 스크립트를 전혀 필요가 없습니다. 이 간단한 형식은 XSLT가 직접 처리 할 수있는 형식입니다.

<td> 
    <xsl:choose> 
     <xsl:when test="string-length(Date) = 4"> 
     <xsl:text>01/01/</xsl:text> 
     <xsl:value-of select="Date" /> 
     </xsl:when> 
     <xsl:otherwise> 
     <xsl:value-of select="substring(Date, 7, 2)" /> 
     <xsl:text>/</xsl:text> 
     <xsl:value-of select="substring(Date, 5, 2)" /> 
     <xsl:text>/</xsl:text> 
     <xsl:value-of select="substring(Date, 1, 4)" /> 
     </xsl:otherwise> 
    </xsl:choose> 
    </td> 

아니면이 대신이 일을

...

<td><xsl:value-of select="Date" /></td> 

이 작업을 수행 ... ...

<td> 
    <xsl:choose> 
     <xsl:when test="string-length(Date) = 4"> 
     <xsl:value-of select="concat('01/01/', Date)" /> 
     </xsl:when> 
     <xsl:otherwise> 
     <xsl:value-of select="concat(substring(Date, 7, 2), '/', substring(Date, 5, 2), '/', substring(Date, 1, 4))" /> 
     </xsl:otherwise> 
    </xsl:choose> 
    </td> 
+0

정말 고마워요! – user4485863

+0

당신은 어떻게 모든 회의에 다른 테이블을 만들어야한다는 것을 암시하기 위해 제안합니까? 코드 dupplcating없이. – user4485863

+0

당신은 Muenchian Grouping이라는 기법을 먼저 읽어야합니다. 국가별로 앨범을 그룹화 할 것입니다. http://www.jenitennison.com/xslt/grouping/muenchian.html을 참조하십시오. 한번 읽어보십시오. 그런 다음 다시 읽으십시오. –