Эта таблица стилей:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:html="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="html">
<xsl:strip-space elements="*"/>
<xsl:preserve-space elements="translation html:*"/>
<xsl:key name="kResourceById" match="resource" use="@id"/>
<xsl:variable name="vConfig" select="/config"/>
<xsl:variable name="vCatalog" select="document('catalog.xml')"/>
<xsl:template match="/">
<xsl:apply-templates select="document('layout.xml')/node()"/>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="html:*[@id]">
<xsl:variable name="vCurrent" select="."/>
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:for-each select="$vCatalog">
<xsl:variable name="vResource"
select="key('kResourceById',$vCurrent/@id)"/>
<xsl:apply-templates
select="($vResource/translation[@xml:lang=$vConfig/lang]
|$vCurrent[not($vResource)])/node()"/>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="*[not(self::html:*)]">
<xsl:apply-templates
select="$vConfig/*[name()=name(current())]/node()"/>
</xsl:template>
</xsl:stylesheet>
С этим входом:
<config>
<lang>en</lang>
<sn>1</sn>
<en>10</en>
</config>
А catalog.xml
:
<catalog>
<resource id="str1">
<translation xml:lang="en"
>enter number between <sn/> and <en/>.</translation>
<translation xml:lang="lt"
>iveskite skaiciu tarp <sn/> ir <en/>.</translation>
</resource>
</catalog>
А layout.xml
:
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form>
<label id="str1"/>
<input id="val1" type="input"/>
<input type="submit"/>
</form>
</body>
</html>
Выход:
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form>
<label id="str1">enter number between 1 and 10.</label>
<input id="val1" type="input"></input>
<input type="submit"></input>
</form>
</body>
</html>
С этим входом:
<config>
<lang>lt</lang>
<sn>20</sn>
<en>30</en>
</config>
Выход:
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form>
<label id="str1">iveskite skaiciu tarp 20 ir 30.</label>
<input id="val1" type="input"></input>
<input type="submit"></input>
</form>
</body>
</html>