I have XSLT 1.0 standard. I have one dynamic XML from server which is quite simple and second XML as configuration. Base on first one (which is dynamic) I have to pick up proper nodes information from second one. This is first document:
<?xml version="1.0" encoding="UTF-8" ?>
<response>
<response>SUCCESS</response>
<responsedata>
<hit>
<url>http://domain.com/page.html</url>
<id>2437</id>
<title>Page title</title>
<language>en</language>
...
...
</hit>
</responsedata>
</response>
Second configuration XML is for footer, header divided by languages. Something like that:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<set id="local">
<header>
<en>
<![CDATA[
<div id="header">
<p>English code</p>
</div>
]]>
</en>
<fr>
<![CDATA[
<div id="header">
<p>French code</p>
</div>
]]>
</fr>
</header>
</set>
</config>
I need pick up proper language depended code from second XML. I tried following code and it doesn't work:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" encoding="utf-8" indent="yes" doctype-system="about:legacy-compat" />
<xsl:variable name="configuration" select="document('settings.xml')/config/set[@id='local']" />
<xsl:variable name="lang" select="response/responsedata/hit/language" />
<xsl:template name="getvalueofnode">
<xsl:param name="path" />
<xsl:param name="context" select="$configuration" />
<xsl:choose>
<xsl:when test="contains($path,'/')">
<xsl:call-template name="getvalueofnode">
<xsl:with-param name="path"
select="substring-after($path,'/')" />
<xsl:with-param name="context"
select="$context/*[name()=substring-before($path,'/')]" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<p>value: <xsl:value-of select="$context/*[name()=$path]" disable-output-escaping="yes" /></p>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="/">
<xsl:element name="html">
<xsl:attribute name="lang"><xsl:value-of select="$lang" /></xsl:attribute>
<xsl:element name="head">
<xsl:attribute name="lang"><xsl:value-of select="$lang" /></xsl:attribute>
</xsl:element>
<xsl:element name="body">
<xsl:attribute name="lang"><xsl:value-of select="$lang" /></xsl:attribute>
<p>lang: <xsl:value-of select="$lang" /></p>
<p>
<xsl:call-template name="getvalueofnode">
<xsl:with-param name="path" select="concat('/header/',$lang)" />
</xsl:call-template>
</p>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
If some one has any suggestion or solution it will be fantastic.