views:

726

answers:

4

I have an ASP.NET web app where the back end data (XML format) is transformed using XSLT, producing XHTML which is output into the page.

Simplified code:

XmlDocument xmlDoc = MyRepository.RetrieveXmlData(keyValue);
XslCompiledTransform xsl = new XslCompiledTransform();
xsl.Load(pathToXsl, XsltSettings.TrustedXslt, null);
StringWriter stringWriter = new StringWriter();
xsl.Transform(xmlDoc, null, stringWriter);
myLiteral.Text = stringWriter.ToString();

Currently my XSL file contains the XHTML markup elements, as well as text labels, which are currently in English. for example:

<p>Title:<br />
  <xsl:value-of select="title"/>
</p>
<p>Description:<br />
  <xsl:value-of select="desc"/>
</p>

I would like the text labels (Title and Description above) to be localized. I was thinking of using .NET resource files (.resx), but I don't know how the resx string resources would get pulled in to the XSLT when the transformation takes place.

I would prefer not to have locale-specific copies of the XSLT file, since that means a lot of duplicate transformation logic.

(NOTE: the XML data is already localized, so I don't need to change that)

A: 

Replace the text in the XSLT files with a placeholder element and then write another localizing transformation that takes the resx file and uses it to replace the placeholders with the desired piece of text.

<p><localized name="title"/>:<br />
  <xsl:value-of select="title"/>
</p>
<p><localized name="desc"/>:<br />
  <xsl:value-of select="desc"/>
</p>
ctford
A: 

Since a .Resx file is an XML file you could use it as another source for the XSLT, by using the document function.

Paulo Manuel Santos
+1  A: 

Please see my blog on Ektron's dev center: Localizing text in an XSLT

Doug D
This is not a practical solution. The resource file has to be distributed along with the solution if you do it this way.
SDX2000
A: 

<p><localized name="title"/>:<br /> <xsl:value-of select="title"/> </p> <p><localized name="desc"/>:<br /> <xsl:value-of select="desc"/> </p>

I need to convert xsl select value of localized format.I am trying as following code...

<xsl:value-of select="<localized name="title"/>" /> <xsl:value-of select="<localized name="desc"/>"/>

showing xsl tag was not closed... how can I do this?

Thanks.

mrd