I've got a relatively simple concept going here: I have one xml document with tags that I want to translate into more meaningful words. The translations are in another xml document. An XSL transformation takes care of matching the tag to its translation.
Here's (part of) the XML document that needs its tags translated.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<NewDataSet>
<Person>
<id>1</id>
<firstname>Michael</firstname>
<lastname>Gradek</lastname>
<birthdate>1980-11-13T00:00:00.0000000-05:00</birthdate>
</Person>
</NewDataSet>
Here's the XML document that does the translation
Code:
<?xml version="1.0" encoding="UTF-8"?>
<localization>
<datatranslations>
<element name="firstname">
<en>First Name</en>
<fr>Prénom</fr>
</element>
<element name="lastname">
<en>Last Name</en>
<fr>Nom</fr>
</element>
<element name="birthdate">
<en>Birth Date</en>
<fr>Date de Naissance</fr>
</element>
</datatranslations>
</localization>
Here's the XSL that fails...
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:param name="localization_url" select="'blackbook_localization.xml'" />
<xsl:variable name="trans_doc" select="document($localization_url)/localization/datatranslations" />
<xsl:template match="/">
<xsl:call-template name="simpledisplay" />
</xsl:template>
<xsl:template name="simpledisplay">
<xsl:for-each select="//NewDataSet/*">
<div style="border: 1px solid #FF0000;">
<xsl:for-each select="*[not(contains(name(), 'id'))]">
<xsl:value-of select="name()" />:
<xsl:value-of select="$trans_doc/element[@name=name()]/en" />:
<xsl:value-of select="." />
<br />
</xsl:for-each>
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The problem is the line
<xsl:value-of select="$trans_doc/element[@name=name()]/en" />
It returns nothing.
$trans_doc/element works properly, I'm able to iterate through its contents.
All the @name attributes have values, and all the calls to
name() also return the proper values.
If I type
<xsl:value-of select="$trans_doc/element[@name='firstname']/en" />, I get the expected result, same for
<xsl:value-of select="$trans_doc/element[@name='lastname']/en" />.
But when I use
name() instead of hardcoding the value, it fails... What am I doing wrong?
Thanks for your help!
Mike