This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Translating grammars XML in others languages


Hello!!!


I have some problems with my aplicattion in XSL.

I will show that I'm doing to facility my explanation:

We have in Brazil a Community that change informations about Science and
Technology in XML, named LMPL.
We have some patterns XML defined by this Community (LMPL) to ours Units of
Informations in Science and Tecnology.
With this patterns represented in XML, We have a application that generate a
XML document. Good, until hear...nothing problems!!!
This aplicattion was been used by others countries with a Spanish language,
and others languages too, and we was doing a translate of this patterns XML,
represented in XML Schema, to a new language - Spanish, and after others.
For this, We are defining a dictionary that say that "CURRICULO" is the same
that "CURRICULUM". This dictionary will be used to do the translating the
XML Schema. "Until hear too... nothing problems".

With the my pattern XML translated to a new language, as Spanish, I need to
adapt my applications to be compatible with this news patterns (represented
in XML Schema).

I thinked in to do a style sheet that get the document XML and translate
only it grammar.
With this I don't need to change all our application, we only generate a
document in XML, and after translate it language grammar (Spanish or other).
This style sheet will read the informations to the translate in a document
XML (named dictionary.xml). When I need to translate a document XML to a new
language, I only specify the translate in the dictionary XML. Then, I do
only one application, and specify the translatte in document XML, and have
my application generating documents XML in many grammars XML.
This idea was implemented for me, and worked!! The following, I show how I
do this.

Document XML (curriculo.xml) + Dictionary.xml = Document XML Translated
(translated.xml).
(But of codes follow to be a piece of the work, I sugest that this code be
copied in a file, and opened in a Editor XML, to be better see).
Obs.:

curriculo.xml
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----
<?xml version="1.0" encoding="ISO-8859-1"?>
<CURRICULO-VITAE SISTEMA-ORIGEM-XML="LATTES_OFFLINE"
DATA-ATUALIZACAO="14062002" HORA-ATUALIZACAO="110926"
xmlns:lattes="http://www.cnpq.br/2001/XSL/Lattes";>
<DADOS-GERAIS NOME-COMPLETO="Teste dos Lattes"
NOME-EM-CITACOES-BIBLIOGRAFICAS="LATTES, T." NACIONALIDADE="B"
CPF="12345678909" PAIS-DE-NASCIMENTO="Brasil" UF-NASCIMENTO="SP"
CIDADE-NASCIMENTO="São Paulo" DATA-NASCIMENTO="27041980" SEXO="MASCULINO"
NUMERO-IDENTIDADE="25222525" ORGAO-EMISSOR="SSP" UF-ORGAO-EMISSOR="SP"
DATA-DE-EMISSAO="09091990" NUMERO-DO-PASSAPORTE="" NOME-DO-PAI="Nome do Pai"
NOME-DA-MAE="Nome da Mãe" PERMISSAO-DE-DIVULGACAO="SIM"
OUTRAS-INFORMACOES-RELEVANTES="Outras informações relevantes"/>
</CURRICULO-VITAE>

dictionary.xml
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----

<?xml version="1.0" encoding="ISO-8859-1"?>
<CURRICULO-VITAE CURRICULO-VITAE="CURRICULUM"
SISTEMA-ORIGEM-XML="SYSTEM-ORIGIN-XML" DATA-ATUALIZACAO="DATE-UPDATE"
HORA-ATUALIZACAO="TIME-UPDATE" xmlns:lattes="xmlns:lattes">
<DADOS-GERAIS DADOS-GERAIS="GERAL-DATA" NOME-COMPLETO="FULL-NAME"
NOME-EM-CITACOES-BIBLIOGRAFICAS="NAME-PUBLISH" NACIONALIDADE="NACIONALIDADE"
CPF="IDENTIFICATION-DOCUMENT" PAIS-DE-NASCIMENTO="COUNTRY-NASC"
UF-NASCIMENTO="STATE-NASC" CIDADE-NASCIMENTO="CITY"
DATA-NASCIMENTO="DATE-BIRTHDAY" SEXO="GENDER"
NUMERO-IDENTIDADE="IDENTIFICATION-NUMBER" ORGAO-EMISSOR="ORGAN-EMITTER"
UF-ORGAO-EMISSOR="STATE-ORGAN-EMITTER" DATA-DE-EMISSAO="DATE-EMITTER"
NUMERO-DO-PASSAPORTE="PASSPORT-NUMBER" NOME-DO-PAI="FATHER-NAME"
NOME-DA-MAE="MOTHER-NAME" PERMISSAO-DE-DIVULGACAO="PERMITED-INFORMATION"
OUTRAS-INFORMACOES-RELEVANTES="OTHERS-INFORMATIONS">
<TOKEN>
<SEXO>
<TEXTO ORIGINAL="MASCULINO" TRADUZIDO="MALE"/>
<TEXTO ORIGINAL="FEMININO" TRADUZIDO="FEMALE"/>
</SEXO>
</TOKEN>
</DADOS-GERAIS>
</CURRICULO-VITAE>


translator.xsl
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="xml" encoding="ISO-8859-1"/>

<xsl:param name="PNmeDocRegras">dictionary.xml</xsl:param>

<xsl:template match="CURRICULO-VITAE">

 <xsl:variable name="DocRegras" select="$PCntdDocRegras"/>

 <!-- CURRICULO (INICIO) -->
 <xsl:text disable-output-escaping="yes">&lt;</xsl:text>
 <xsl:value-of select="$DocRegras/CURRICULO-VITAE/@CURRICULO-VITAE"/>
 <xsl:text> </xsl:text>

 <!-- @SISTEMA-ORIGEM-XML -->
 <xsl:value-of select="$DocRegras/CURRICULO-VITAE/@SISTEMA-ORIGEM-XML"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@SISTEMA-ORIGEM-XML"/>
 <xsl:text>" </xsl:text>

 <!-- @DATA-ATUALIZACAO -->
 <xsl:value-of select="$DocRegras/CURRICULO-VITAE/@DATA-ATUALIZACAO"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@DATA-ATUALIZACAO"/>
 <xsl:text>" </xsl:text>

 <!-- @HORA-ATUALIZACAO -->
 <xsl:value-of select="$DocRegras/CURRICULO-VITAE/@HORA-ATUALIZACAO"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@HORA-ATUALIZACAO"/>
 <xsl:text>" </xsl:text>

 <xsl:text disable-output-escaping="yes">&gt;</xsl:text>

 <!-- CHAMADA DADOS-GERAIS -->
 <xsl:apply-templates select="DADOS-GERAIS">
  <xsl:with-param name="DocRegras"
select="$DocRegras/CURRICULO-VITAE/DADOS-GERAIS"/>
 </xsl:apply-templates>

 <!-- CURRICULO (FIM) -->
 <xsl:text disable-output-escaping="yes">&lt;/</xsl:text>
 <xsl:value-of select="$DocRegras/CURRICULO-VITAE/@CURRICULO-VITAE"/>
 <xsl:text disable-output-escaping="yes">&gt;</xsl:text>
</xsl:template>

<!-- DADOS-GERAIS -->
<xsl:template match="DADOS-GERAIS">
 <xsl:param name="DocRegras"/>
 <!-- DADOS-GERAIS (INICIO) -->
 <xsl:text disable-output-escaping="yes">&lt;</xsl:text>
 <xsl:value-of select="$DocRegras/@DADOS-GERAIS"/>
 <xsl:text> </xsl:text>

 <!-- @NOME-COMPLETO -->
 <xsl:value-of select="$DocRegras/@NOME-COMPLETO"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@NOME-COMPLETO"/>
 <xsl:text>" </xsl:text>

 <!-- @NOME-EM-CITACOES-BIBLIOGRAFICAS -->
 <xsl:value-of select="$DocRegras/@NOME-EM-CITACOES-BIBLIOGRAFICAS"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@NOME-EM-CITACOES-BIBLIOGRAFICAS"/>
 <xsl:text>" </xsl:text>

 <!-- @CPF -->
 <xsl:value-of select="$DocRegras/@CPF"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@CPF"/>
 <xsl:text>" </xsl:text>

 <!-- @PAIS-DE-NASCIMENTO -->
 <xsl:value-of select="$DocRegras/@PAIS-DE-NASCIMENTO"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@PAIS-DE-NASCIMENTO"/>
 <xsl:text>" </xsl:text>

 <!-- @UF-NASCIMENTO -->
 <xsl:value-of select="$DocRegras/@UF-NASCIMENTO"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@UF-NASCIMENTO"/>
 <xsl:text>" </xsl:text>

 <!-- @CIDADE-NASCIMENTO -->
 <xsl:value-of select="$DocRegras/@CIDADE-NASCIMENTO"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@CIDADE-NASCIMENTO"/>
 <xsl:text>" </xsl:text>

 <!-- @DATA-NASCIMENTO -->
 <xsl:value-of select="$DocRegras/@DATA-NASCIMENTO"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@DATA-NASCIMENTO"/>
 <xsl:text>" </xsl:text>

 <!-- @SEXO (TOKEN - CONVERTER CONTEÚDO) -->
 <xsl:variable name="varSexo" select="@SEXO"/>
 <xsl:if test="$varSexo != ''">
  <xsl:value-of select="$DocRegras/@SEXO"/>
  <xsl:text>="</xsl:text>
   <xsl:value-of select="$DocRegras/TOKEN/SEXO/TEXTO[@ORIGINAL =
$varSexo]/@TRADUZIDO"/>
  <xsl:text>" </xsl:text>
 </xsl:if>

 <!-- @NUMERO-IDENTIDADE -->
 <xsl:value-of select="$DocRegras/@NUMERO-IDENTIDADE"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@NUMERO-IDENTIDADE"/>
 <xsl:text>" </xsl:text>

 <!-- @ORGAO-EMISSOR -->
 <xsl:value-of select="$DocRegras/@ORGAO-EMISSOR"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@ORGAO-EMISSOR"/>
 <xsl:text>" </xsl:text>

 <!-- @UF-ORGAO-EMISSOR -->
 <xsl:value-of select="$DocRegras/@UF-ORGAO-EMISSOR"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@UF-ORGAO-EMISSOR"/>
 <xsl:text>" </xsl:text>

 <!-- @DATA-DE-EMISSAO -->
 <xsl:value-of select="$DocRegras/@DATA-DE-EMISSAO"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@DATA-DE-EMISSAO"/>
 <xsl:text>" </xsl:text>

 <!-- @NUMERO-DO-PASSAPORTE -->
 <xsl:value-of select="$DocRegras/@NUMERO-DO-PASSAPORTE"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@NUMERO-DO-PASSAPORTE"/>
 <xsl:text>" </xsl:text>

 <!-- @NOME-DO-PAI -->
 <xsl:value-of select="$DocRegras/@NOME-DO-PAI"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@NOME-DO-PAI"/>
 <xsl:text>" </xsl:text>

 <!-- @NOME-DA-MAE -->
 <xsl:value-of select="$DocRegras/@NOME-DA-MAE"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@NOME-DA-MAE"/>
 <xsl:text>" </xsl:text>

 <!-- @PERMISSAO-DE-DIVULGACAO -->
 <xsl:value-of select="$DocRegras/@PERMISSAO-DE-DIVULGACAO"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@PERMISSAO-DE-DIVULGACAO"/>
 <xsl:text>" </xsl:text>

 <!-- @OUTRAS-INFORMACOES-RELEVANTES -->
 <xsl:value-of select="$DocRegras/@OUTRAS-INFORMACOES-RELEVANTES"/>
 <xsl:text>="</xsl:text>
 <xsl:value-of select="@OUTRAS-INFORMACOES-RELEVANTES"/>
 <xsl:text>" </xsl:text>


 <xsl:text disable-output-escaping="yes">/&gt;</xsl:text>
</xsl:template>

</xsl:stylesheet>


translated.xml (result)
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----
<?xml version="1.0" encoding="ISO-8859-1"?>
<CURRICULUM SYSTEM-ORIGIN-XML="LATTES_OFFLINE" DATE-UPDATE="14062002"
TIME-UPDATE="110926">
<GERAL-DATA FULL-NAME="Teste dos Lattes" NAME-PUBLISH="LATTES, T."
IDENTIFICATION-DOCUMENT="12345678909" COUNTRY-NASC="Brasil" STATE-NASC="SP"
CITY="São Paulo" DATE-BIRTHDAY="27041980" GENDER="MALE"
IDENTIFICATION-NUMBER="25222525" ORGAN-EMITTER="SSP"
STATE-ORGAN-EMITTER="SP" DATE-EMITTER="09091990" PASSPORT-NUMBER=""
FATHER-NAME="Nome do Pai" MOTHER-NAME="Nome da Mãe"
PERMITED-INFORMATION="SIM" OTHERS-INFORMATIONS="Outras informações
relevantes"/>
</CURRICULUM>

----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
--------------------------------------------

Well, that I need to do now is to be the reverse process, is, to implement a
style sheet that read a document XML with grammar in SPANISH or ENGLISH, and
find in the dictionary (with translating of PORTUGUESE to SPANISH (or
ENGLISH)) the tag translated, and transform the document to the language
PORTUGUESE.

Then, my style sheet needs to read a dictionary.xml and to apply the
template with the name that it found in the dictionary.
And my doubt is this, how to apply a template with a value of the a
variable???
Example:

<xsl:template match="/">
 <!-- Get the name of root element to apply the template -->
 <xsl:variable name="vElemRoot"
select="$DocRegras/CURRICULO-VITAE/@CURRICULO-VITAE"/>
 <!-- Apply the template with a value of the variable --> <!-- This don't
word - Need to be a qname-->
 <xsl:apply-templates select="$vElemRoot"/>
</xsl:template>

People, if someone to have a idea of how to resolve this problem I thanks a
lot!! Some idea is welcome!!!!
My problem is exactly this. Make a style sheet to translate a grammar of a
document of PORTUGUESE -> SPANISH, and other to do reverse process, to
translate a grammar of a document of SPANISH -> PORTUGUESE.

I hope to have explained the lighter possible. (Sorry by possible grammars
errors).


Thanks very much!!!


Paulo Henrique Bermejo.



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]