[xsl] Localising Submit/Clear buttons in html

Subject: [xsl] Localising Submit/Clear buttons in html
From: Ian_blizard@xxxxxx (Ian Blizard)
Date: Mon, 12 Nov 2001 14:43:38 +0000
Hello list,

Thanks to Jeni for solving my last problem, roses and chocolates are on 
the way if you can help solve this one!

I'm using a mechanism proposed by IBM DeveloperWorks for localising 
markup.  It consists of one dictionary file containing the localised 
strings, and a localisation XSL file which parses a HTML file for 
"nlsid" tags for any node, if it finds a corresponding entry in the 
dictionary file it will replace the content of the node with the content 
from the dictionary.

The params $doc-file and $currentLocale are set before the 
transformation:

e.g trans.setAttribute("doc-file", "my_doc_file.xml");

etc.

e.g.

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

	<xsl:param name="doc-file"/>
	<xsl:param name="currentLocale"/>

	<xsl:template match="text()|@*"><xsl:value-of 
select="."/></xsl:template>
	<xsl:template match="*|node()" priority="1">
		<xsl:copy>
			<xsl:copy-of select="@*"/><xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>
	<xsl:template match="/"><xsl:apply-templates/></xsl:template>

	<xsl:template match="*[@nlsid]" priority="5">
	   <xsl:copy>
		<xsl:for-each select="@*">
			<xsl:if test="name()!='nlsid'">
				<xsl:copy-of select="."/>
			</xsl:if>
		</xsl:for-each>
		<xsl:apply-templates select="./*"/>
		<xsl:variable name="myKey" select="@nlsid"/>
		<xsl:choose>
		<xsl:when test="document($doc-file)/locale/*[name()=$myKey]">
                <xsl:value-of 
select="document($doc-file)/locale/*[name()=$myKey]/*[name()=$currentLoc
ale]"/>
		</xsl:when>
		<xsl:otherwise>
		 <xsl:value-of select="."/>
		</xsl:otherwise>
		</xsl:choose>
	    </xsl:copy>	
	</xsl:template>

</xsl:stylesheet>

Now that's all well and good if you want to localise the <title> node in 
HTML, e.g.

<title nlsid="PAGE_TITLE">This is my page</title>

However, when you're creating a page with forms and you need to localise 
buttons, they take their textual value from the 'Value' attribute:

<input type="submit" value="Click here to submit!"/>

Say, I add a 'nlsid' attribute to the button:

<input type="submit" value="Click here to submit!" 
nlsid="SUBMIT_BUTTON"/>

With current processing is there a simple way to populate the 'value' 
attribute with the dictionary lookup?

-Ian.





 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread