我如何讓XSLT向用戶顯示本地化的日期(在用戶代理的語言環境中)。如何顯示本地化日期?
例如,給定在ISO格式的XML date
(2013-09-04T10:46:19.658
):
<?xml version="1.0" encoding="utf-8"?>
<Stuff>
<Created>2013-09-04T10:46:19.658</Created>
</Stuff>
並且樣式表的開端:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" version="5.0" doctype-system="about:legacy-compat"/>
<xsl:template match="/Stuff">
<html>
<body>
Created: <xsl:value-of select="format-date('Created')"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
所需的輸出取決於,當然,在區域設置的用戶代理(例如客戶瀏覽器):
Created: 01/11/34
Created: 05.09.13
Created: 05.09.2013
Created: 05/09 2013
Created: 05/09/2013
Created: 05-09-13
Created: 05-09-2013
Created: 09.05.2013
Created: 09/05/2013
Created: 13.09.05
Created: 2013.09.05
Created: 2013.09.05.
Created: 2013/09/05
Created: 2013/9/5
Created: 2013-09-05
Created: 2013-9-5
Created: 29/10/34
Created: 5. 9. 2013
Created: 5.09.2013
Created: 5.9.2013
Created: 5.9.2013 г.
Created: 5.9.2013.
Created: 5//09//2013
Created: 5/09/2013
Created: 5/9/2013
Created: 5/9/2556
Created: 5-9-2013
Created: 9/5/2013
XSLT是否支持本地化?
它在客戶端上運行
將XML轉換爲HTML發生在客戶端上。由於轉換髮生在客戶端上,客戶端(顯然)知道它自己的區域設置。
例如,客戶機被賦予一些xml
:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='/Styles/Contoso_Handheld.xslt' media='handheld'?>
<?xml-stylesheet type='text/xsl' href='/Styles/Contoso_iPhone.xslt' media='only screen and (max-device-width: 480px)'?>
<?xml-stylesheet type='text/xsl' href='/Styles/Contoso.xslt' media='all'?>
<Stuff>
<Created>2013-09-04T10:46:19.658</Created>
</Stuff>
通知的線,其中在指示使用哪個XSLT
客戶端。
<?xml-stylesheet type='text/xsl' href='/Styles/Contoso_Handheld.xslt' media='handheld'?>
<?xml-stylesheet type='text/xsl' href='/Styles/Contoso_iPhone.xslt' media='only screen and (max-device-width: 480px)'?>
<?xml-stylesheet type='text/xsl' href='/Styles/Contoso.xslt' media='all'?>
的用戶代理取的XSLT,將XML,並將其顯示給用戶。所有這些處理都發生在客戶端的語言環境中。