We are building a system that gets XML data from a database, uses XSLT to transform it to XHTML and at the same time use an external XML file to retrieve culture-specific labels (translations for our labels).
Short Question
Does the translation/culture-specific system seem logical ? Efficient ?
Any alternative concepts are welcome (in this specific context)
Detailed Question
XML data
<page id="55" objecttype="ChristianOrthodoxMonument">
<field name="uniquename">some unique name here</field>
.. multiple field elements here ..
</page>
XML culture-labels
<ChristianOrthodoxMonument>
<uniquename culture-1="Ονομασία" culture-2="Unique name" />
<birthdate culture-1="Ημ/νία γέννησης" culture-2="Date of birth" />
</ChristianOrthodoxMonument>
now in XSLT i pass the cultureid parameter to be used for the mapping to the labels.
XSLT (example snippet)
<xsl:param name="cultureid" select="1" />
<xsl:variable name="objecttype" select="/page/@objecttype" />
and to map to the external file which is included with
<xsl:variable name="culture" select="document('cultural-labels.xml')" />
i created a pseudo dynamic xpath
<xsl:template name="translate">
<xsl:variable name="nodename" select="@name" />
<xsl:value-of select="$culture/*[name()=$objecttype]/*[name()=$nodename]/@*[name()=concat('culture-',$cultureid)]" />
</xsl:template>
which i call whenever i want to get the label for a field.
Question A : is this xpath efficient or overkill ? overcomplicated ?
Question B : does this model seem right or am i missing something vital that will prove to be an obstacle in the future ?
Question C : Is there any theory/example on similar mapping techniques to external XML files ?
2nd Update with composite key usage
key
<xsl:key name="find-node" match="*" use="concat(name(..),'!',name())" />
lookup
<xsl:template name="lookup-label">
<xsl:param name="objecttype" />
<xsl:variable name="nodename" select="@name" />
<xsl:for-each select="$culture">
<xsl:value-of select="key('find-node',concat($objecttype,'!',$nodename))/@*[name()=$culturefield]" />
</xsl:for-each>
</xsl:template>
is this an improvement ?
Yes.
It can be efficient — not exactly your implementation.
No, it isn’t efficient, because the whole XML document will be traversed many times to find specific objecttype nodes.
No.
The model is generally OK.
There are many examples of efficient lookup based on keys — even at SO. Also see this one.