tags:

views:

30

answers:

2

I'm using an XSL file to do the rendering of an ASP.NET webpart that I made, but now I want to localize the strings inside that XSL file:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:siteInfo="urn:siteInfo" version="1.0">
  <xsl:output method="html" omit-xml-declaration="no"/>
  <xsl:template match="*|/">
    <p>
     Project name: <xsl:value-of select="siteInfo:GetProjectName()"/>
    </p>

In the above example I want to localize "Project name". The language in which I'm working is C# and this is the snippet I use for transforming:

XslCompiledTransform transformationEngine = new XslCompiledTransform();
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = CredentialCache.DefaultNetworkCredentials;
transformationEngine.Load(XslUrl, new XsltSettings(true, true), resolver);
XsltArgumentList args = new XsltArgumentList();
args.AddExtensionObject("urn:siteInfo", siteInfo);
transformationEngine.Transform(xmlDocument, args, ms);

Is it possible to do localization through resource (resx) files in that XSL file? In the rest of my project I'm using the following line to insert localized strings:

HttpContext.GetGlobalResourceObject(resourceName, resourceKey).ToString();

Kind regards,

Jeroen

A: 

XSLT is incognizant of "resource files".

It is possible to use one or more XML files that contain the necessary localization and to access them during transformation using the document() function and the key() function to "do the translation".

I have many times answered similar question and given examples, but can't find them immediately now. Thus here is another example: http://www.dpawson.co.uk/xsl/sect2/N4852.html#d6180e1251

Dimitre Novatchev
I really want to use just one XSL file to avoid unnecessary overhead + it's the way everything works in SharePoint. Sample SharePoint XML (something I'd like to achieve, where all $Resources:xxx; are being replaced by their respective translation): <?xml version="1.0" encoding="utf-8"?><Project Title="$Resources:onet_TeamWebSite;" Revision="2" ListDir="$Resources:core,lists_Folder;" xmlns:ows="Microsoft SharePoint">Would the only way be to do some kind of search with regex, then replacing it?
Jeroen Van Bastelaere
Most probably this can be done nicely but you need to put a more complete example (formatted) in your question. Please, indicate what is the main problem -- is it organizing the definitions of terms and their translations to multiple languages? Or is it the constructing of the appropriate filename? Please, be as specific as possible.
Dimitre Novatchev
A: 

XSL:

    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
               xmlns:siteInfo="urn:siteInfo"
               version="1.0">
  <xsl:output method="html" omit-xml-declaration="no"/>
  <xsl:template match="*|/">
    <style type="text/css">
      .siteInfoHeader {
       font-weight: bold;
       font-size: 10pt;
       margin-bottom: 6pt;
      }
      #siteInfo p {
       margin-top: 0;
       margin-bottom: 6pt; 
      }
    </style>
    <div id="siteInfo">
      <h3 class="siteInfoHeader">$Resources:GWOSXmlWebPartResources,Objectives;:</h3>
      <p>
        <xsl:value-of select="siteInfo:GetObjectives()"/>
      </p>
      <h3 class="siteInfoHeader">$Resources:GWOSXmlWebPartResources,Audience;:</h3>

The resources have been done through the standard SharePoint way to handle resources in XML ($Resources:ResourceFile,Key;). Before performing the XSL transformation there is the possibility to invoke a standard SharePoint function GetLocalizedXmlDocument of the object Microsoft.SharePoint.SPXmlDocCache through reflection, this will hand back an XmlDocument object which has been parsed through the "localization filter", using the standard resources inside the 12-hive/resources. Thanks to Tom Nys for helping me out on this.

Jeroen Van Bastelaere