我正在編碼一個網站,該網站的語言字符串以xml文件分隔。根據不同的語言,我包括一個或另一個。這沒有問題。使用XML和XSLT格式化字符串,如PHP中的sptrinf()
順便說一下,這個網站是一個動態的,所以會有例如像字符串你好ipalaus!英文,如Bienvenido ipalaus!等等。在這種情況下,我們有詞的順序相同,但在某些情況下可能會名字符串,字符串名稱,字符串名稱字符串 ...
有無論如何回答什麼sprintf()
確實在PHP?在PHP中,我們有這樣的:
<?php
$name = "ipalaus";
$string = "Welcome %s";
echo sprintf($string, $name);
// OUTPUTS: Welcome ipalaus
?>
我想在我的index.en.xml一些像:
<language>
<welcome>Welcome %s</welcome>
</language>
在我INDEX.XML,與PHP產生的一個,將有:
<index>
<locale>en</locale>
<welcome>ipalaus</welcome>
</index>
而且,在XSLT文件,代表歡迎ipalaus。
其實,在我的XSLT文件,我用這個來加載語言:
<xsl:param name="language" select="document(concat('../lang/', $locale, '/index.xml'))" />
訪問的價值觀與:<xsl:value-of select="$base/language/welcome" />
。
預先感謝您!
編輯:一種關於他完全有效的響應問題亞歷杭德羅例如:
<index>
<video>
<author>ipalaus</author>
</video>
<video>
<author>Alejandro</author>
</video>
</index>
而且語言文件:
<language>
<video>
<made>This videos is made by <author/></made>
<random>Another string</random>
</video>
</language>
更多鈔票複製http://stackoverflow.com/questions/3986408/how-to-fill-text- templates-using-xslt – 2010-11-02 14:24:57
我完全不理解它。它發佈了一個示例,但我正在尋找一種將其解析爲大規模的方法,因此我不必爲每個變量重複一次,因爲在大型項目中可能會非常困難。請注意,必須混合使用不同的XML文件。無論如何? – ipalaus 2010-11-02 14:48:51
@Alejandro,你沒有看到我能做的事嗎?提前致謝! – ipalaus 2010-11-02 17:46:08