xml PARSeR EXAMPLE 1:  trANSLAtING XML ELeMENTS

 

The following example shows how to specify that an XML element in the XML parser file (XSL style-sheet) is translatable.  The use of the "rwt:elementTU" instruction attribute is also demonstrated.

 

Sample name:  "Sample1-Elements"

Location of sample file:  ...\Samples\Developing\XMLParser\Sample1-Elements

 

SAMPLE FILE

DESCRIPTION

1. "Sample.xml"

Input: An XML file to be translated and that is to be read by the XML parser.

2. "XMLParser-Keywords.xsl"

The XML parser  for "Samples.xml", an XSL extensible stylesheet.

3. "msxsl.exe"

Command line utility to run the XSL transformation.

4. "Transform.bat"

Batch file to run the XSL transformation.

5. "Transformed.xml"

Output: The transformed XML file containing RC-WinTrans instruction attributes.  Run the "Transform.bat" batch file to generate the file.

 

Related topics...

 

 

XML Parser

File name: "XMLParser-Keywords.xsl"

Parsed elements that are to be specified as translatable:  <Description> and <Unit>.

 

Identifier used for an element (also: resource name):

<element name> + '(' + <value of Name element> + ')'

Example: "Description (Spot1)"; "Unit (Spot1)"

 

TEXT COLORS:

Black: Code of the template file for the XML parser.

Blue: Code specific to the XML file being parsed.

Green: XSL command used to add an RC-WinTrans instruction attribute.

Rose/Pink: The name of the RC-WinTrans instruction attribute.

^ Top ^

<?xml version="1.0" ?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

                xmlns:fn="http://www.w3.org/2005/02/xpath-functions"

                version="1.0">

   <xsl:output encoding="utf-8"/>

 

   <!-- Match the root node -->

   <xsl:template match="/">

      <xsl:text>

   </xsl:text>

 

   <xsl:apply-templates select="*|@*|text()|comment()|processing-instruction()"/>

   </xsl:template>

   <!-- match everything else -->

   <xsl:template match="*|@*|text()|comment()|processing-instruction()">

      <xsl:copy><xsl:apply-templates

                select="*|@*|text()|comment()|processing-instruction()"/></xsl:copy>

   </xsl:template>

 

<!-- set all 'Description' elements as translatable -->

  <xsl:template match="Description">

   <xsl:element name="{local-name(.)}">

      <xsl:attribute name="rwt:elementTU" namespace = "RC-WinTrans">

                    Description (<xsl:value-of select="../Name"/>)</xsl:attribute>

      <xsl:apply-templates

                select="*|@*|text()|comment()|processing-instruction()"/>

   </xsl:element>

  </xsl:template>

 

<!-- set the 'Unit' element as translatable -->

  <xsl:template match="Unit">

   <xsl:element name="{local-name(.)}">

      <xsl:attribute name="rwt:elementTU" namespace = "RC-WinTrans">

                         Unit (<xsl:value-of select="../Name"/>)</xsl:attribute>

      <xsl:apply-templates

                select="*|@*|text()|comment()|processing-instruction()"/>

   </xsl:element>

  </xsl:template>

 

</xsl:stylesheet>

 

^ Top ^

 

XML File (to be Translated)

File name: "Sample.xml"

Parsed elements that are to be specified as translatable:  <Description> and <Unit>.

 

Identifier used for an element (also: resource name):

<element name> + '(' + <value of Name element> + ')'

Example: "Description (Spot1)"; "Unit (Spot1)"

 

TEXT COLORS:

Black: Code of the template file for the XML parser.

Green: The XML element to be translated.

Rose/Pink: The XML element where the value text is used to build an identifier for the elements to be translated.

 

The item identifier  for the <Description> element will look like this, for example:

"Description (SpotB)";

and the item identifier for the <Unit> element like this (for example): "Unit (SpotB)".

 

<?xml version="1.0" encoding="windows-1252"?>

<Keywords>

   <Keyword>

      <Category>VP_BEGIN_KEY</Category>

      <ReferenceId>86</ReferenceId>

      <Name>SpotB</Name>

      <Description>Adjusted spot kVA on phase @B</Description>

      <Unit>(kVA)</Unit>

    </Keyword>

    <Keyword>

       <Category>SC_BEGIN_KEY</Category>

       <ReferenceId>30</ReferenceId>

       <Name>X0ohm</Name>

       <Description>X0 in ohms</Description>

       <Unit>(ohms)</Unit>

    </Keyword>

</Keywords>

^ Top ^

 

Figure: The RC-WinTrans application where the XML file "Sample.xml" has been added to a translation project (Project Data view, bottom).  The texts of the <Description> and the <Unit> elements are listed in the Text Table view (top).

 

^ Top ^