xslt本地化

编程入门 行业动态 更新时间:2024-10-27 22:27:15
本文介绍了xslt本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 <?xml version="1.0" encoding="UTF-8"?> <directory> <employee> <name>Joe Smith</name> <phone>4-0192</phone> </employee> <employee> <name>Sally Jones</name> <phone>4-2831</phone> </employee> </directory>

然后跟随xslt:-

<?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="www.w3/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match="directory"> <div>List of Employee<xsl:value-of select="@directory"/> </div> <br/> <table> <tr> <td>Employee Name</td> <td>Contact Details</td> </tr> <xsl:apply-templates select="employee"></xsl:apply-templates> </table> </xsl:template> <xsl:template match="employee"> <tr> <td> <xsl:value-of select="@name"/> </td> <td> <xsl:value-of select="@phone"/> </td> </tr> </xsl:template> </xsl:stylesheet>

我想本地化xslt文本:员工列表,员工姓名和姓名;联系方式

I would like to localize xslt text : List of Employee, Employee Name & Contact Details

如何本地化xslt文本?

How to localize the xslt text?

推荐答案

我可以看到三种方法来做到这一点,哪种方法最好(或者是否有其他方法可供选择)取决于何时以及如何需要最终的xml. :

I can see three ways to do this, which one is best (or if any of these is an alternative) depends on when and how you need the final xml:

以编程方式构造xsl

使用例如 XmlDocument 构建xsl-那么您可以使用常规的字符串资源来填写标签,并可能利用应用程序的区域性设置.

Build the xsl using for example XmlDocument - then you can use regular string resources to fill in the labels, and possibly make use of the culture settings of your application.

将翻译内容嵌入xsl

使用 <xsl:param> 告诉转换要使用哪种语言,然后在每个字符串后放置<xsl:choose>:

<xsl:choose> <xsl:when test="$language='en'">Contact Details</xsl:when> <xsl:when test="$language='sv'">Kontaktuppgifter</xsl:when> <xsl:otherwise>Unknown language <xsl:value-of select="$language"/></xsl:otherwise> </xsl:choose>

在转换中查找翻译

将翻译内容放入其自己的translation.xml的xml文档中:

Put the translations in an xml documents of its own translation.xml:

<strings> <string language="en" key="ContactDetails">Contact Details</string> <string language="sv" key="ContactDetails">Kontaktuppgifter</string> [...] </strings>

然后使用以下内容加载其内容:

Then load it's contents with:

<xsl:variable name="strings" select="document('translation.xml')/strings"/>

...并通过以下方式访问它们:

...and access them with:

<xsl:value-of select="$strings/string[@key='ContactDetails' and @language=$language]"/>

更多推荐

xslt本地化

本文发布于:2023-07-24 13:13:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1203659.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:xslt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!