Re: [xsl] Change Months from English to French [XSLT 1.0]

Subject: Re: [xsl] Change Months from English to French [XSLT 1.0]
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Sat, 31 Jul 2010 16:24:17 +0200
pankaj.c@xxxxxxxxxxxxxxxxxx wrote:

Any direction in this regard will be highly appreciated. (NOTE: Input will be <date-printed>August 2010</date-printed> i.e., Month name [space] Year. Output required is Aout 2010)

As long as that format is ensured it should be easy simply create a secondary XML document which maps the English names to the French names e.g.


<map>
  <!-- put complete mapping here -->
  <month en="August" fr="Aout"/>
</map>

then load that file with the document function e.g.

<xsl:variable name="month-map" select="document('map.xml')"/>


then define a key e.g.


<xsl:key name="mk" match="month" use="@en"/>

then process e.g.

<xsl:template match="date-printed">
  <xsl:copy>
    <xsl:variable name="em" select="substring-before(., ' ')"/>
    <xsl:for-each select="$month-map">
      <xsl:value-of select="key('mk', $em)/@fr"/>
    </xsl:for-each>
    <xsl:value-of select="concat(' ', substring-after(., ' '))"/>
  </xsl:copy>
</xsl:emplate>

--

	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

Current Thread