translate() ?

Hi All

Ive got the contents of a html table which im trying to transform into some kind of XML file.

The table always has 4 cols and the [ position mod 2 =1] will select the 1st and 3rd col which contain a label for the following 2nd or 4th columns

My problem is that im trying to build a new element (col1 or 3) to house its information( cols 2 or 4)

so in the case of


id get col1s name containing col 2 info


Unfortunatly the info is in french so need to strip out/translate the accented chars, spaces or reserved characters.

Can anyone suggest a way that this can be achieved or a better way to reconstruct the data?

Hope you can help.

Who is Participating?
<xsl:template match="td">
<item name="{b}" value="{following-sibling::td}" />

from this you'll have an idea of what characters your are looking to strip...
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
<xsl:output method="xml" version="utf-8" indent="yes"/>
<xsl:param name="char-lists">abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890éè</xsl:param>
<xsl:param name="char-extended">éè</xsl:param>
<xsl:param name="char-replace">ee</xsl:param>
<xsl:param name="char-uppercase">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:param>
<xsl:param name="char-lowercase">abcdefghijklmnopqrstuvwxyz</xsl:param>
<xsl:template match="/">
<xsl:apply-templates select="//tr/td[position() mod 2 = 1][string-length(b) != 0]" />
<xsl:template match="td">
<xsl:variable name="char-target" select="translate(b,$char-lists,'')" />
<xsl:variable name="char-scrubbed" select="translate(b,$char-target,'')" />
<xsl:variable name="char-normal" select="translate($char-scrubbed,$char-extended,$char-replace)" />
<xsl:element name="{translate($char-normal,$char-uppercase,$char-lowercase)}">
<xsl:value-of select="following-sibling::td" />


<?xml version="1.0" encoding="utf-8"?>
  <detailtype>Au calme</detailtype>
  <ville>Entre BLERE et LOCHES </ville>
  <superficie>300 M²</superficie>
  <superficieterrasse>25 M² </superficieterrasse>
  <prix>331 769,00 €</prix>
  <salon>2 M² </salon>
  <cuisine>oui </cuisine>
  <niveau>1 </niveau>
  <anneeconstruction>17ème </anneeconstruction>
  <etatgeneral>bon </etatgeneral>
  <prestations>de qualité </prestations>
  <terrain>arboré. Surface :9600 M² </terrain>
  <taxefonciere>494 € </taxefonciere>

Try it with:-

<xsl:variable name="nodename" select="translate(normalize-space(substring-before(b,':')),' ','_')" />

I think the problem will be with the colon and the spaces in the text.  The above should select out of the text the content preceeding the colon.  Eliminate the leading and trailing whitespace reducing all other whitespace to a single space then replace each of these spaces with an underscore.

metalmickeyAuthor Commented:
I think your right, some of the nodes contain single quotes ' and full stops.

Since the html table should ALWAYS contain the same labels could i use some kind of xml mapping to build the node element names. This would kind of translate the values to english too?

<xsl:variable name="nodename">
<if test="b='Réf.'>reference</xsl:if>

Réf. = reference
Prix : = price

Would something like that work?

first things first, if you are not sure about the element name, make it simple for you:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
<xsl:output method="xml" version="utf-8" />
<xsl:template match="/">
<xsl:apply-templates select="//tr/td[position() mod 2 = 1][string-length(b) != 0]" />
<xsl:template match="td">
<item name="{translate(b,'_:','')}" value="{following-sibling::td}" />


XML Output
<?xml version="1.0" encoding="utf-8"?>
  <item name="Réf." value="05363" />
  <item name="Type " value="Maison" />
  <item name="Détail type " value="Au calme" />
  <item name="Code postal &#xD;&#xA;                " value="37310" />
  <item name="Ville " value="Entre BLERE et LOCHES " />
  <item name="Superficie &#xD;&#xA;                " value="300 M²" />
  <item name="Superficie &#xD;&#xA;                  terrasse " value="25 M² " />
  <item name="Prix " value="331 769,00 €" />
  <item name="Nb chambres &#xD;&#xA;                " value="4" />
  <item name="Nb Salle de bain &#xD;&#xA;                  " value="0" />
  <item name="Nb de pièces &#xD;&#xA;                " value="10" />
  <item name="Nb salle d'eau &#xD;&#xA;                  " value="1" />
  <item name="Séjour " value="oui" />
  <item name="Superficie séjour &#xD;&#xA;                  " value="" />
  <item name="Salon " value="2 M² " />
  <item name="Cheminée " value="oui" />
  <item name="Cuisine " value="oui " />
  <item name="Equipée " value="" />
  <item name="Parking " value="" />
  <item name="Garage " value="" />
  <item name="Niveau " value="1 " />
  <item name="ADSL " value="" />
  <item name="Vue " value="" />
  <item name="Année &#xD;&#xA;                  construction " value="17ème " />
  <item name="Exposition &#xD;&#xA;                " value="" />
  <item name="Etat general &#xD;&#xA;                " value="bon " />
  <item name="Chauffage &#xD;&#xA;" value="fuel" />
  <item name="Prestations &#xD;&#xA;                " value="de qualité " />
  <item name="Terrain  " value="arboré. Surface :9600 M² " />
  <item name="Piscine " value="" />
  <item name="Charges " value="" />
  <item name="Taxe foncière &#xD;&#xA;                  " value="494 € " />
  <item name="Taxe habitation " value="600" />
  <item name="Lycée / école " value="" />
  <item name="Marché " value="" />
  <item name="Commerces " value="" />
  <item name="Cours de tennis " value="" />
  <item name="Autoroute " value="" />
  <item name="Gare  " value="" />

metalmickeyAuthor Commented:
thanks alot.

works a treat!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.