Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6856039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:50:03+00:00 2026-05-27T01:50:03+00:00

I have got an answer from my last question about translating an XML file

  • 0

I have got an answer from my last question about translating an XML file and it inspired me to play with it. I came up with a different solution, but I have the feeling that the two last selects are suboptimal. Can this be done in a nicer way or more efficient?

The stylesheet:

<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:param name="pFrom" select="'en'"/>
  <xsl:param name="pTo" select="'de'"/>


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

  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="@name">
    <xsl:variable name="thisname" select="." />

    <xsl:variable name="entry" select="$translations/translations/entry[attribute::node()[name()=$pFrom and $thisname=.]]"></xsl:variable>
    <xsl:attribute name="name" select="$entry/attribute::node()[local-name() = $pTo]"></xsl:attribute>
  </xsl:template>
</xsl:stylesheet>

The source:

<?xml version="1.0" encoding="UTF-8"?>
<grammar>
  <element name="table" />
  <element name="chair" />
</grammar>

And the translation file (translations.xml):

<?xml version="1.0" encoding="UTF-8"?>
<translations>
    <entry en="table" de="Tisch" fr="Table" />
    <entry en="chair" de="Stuhl" fr="Chaise"/>
</translations>

The result is:

<grammar>
   <element name="Tisch"/>
   <element name="Stuhl"/>
</grammar>

An example: when I go from ‘en’ to ‘de’ and I am at the first name attribute (‘table’) in the source file, I look into the translations file for en entry where en=”table” and select the ‘de’ attribute for the name.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:50:04+00:00Added an answer on May 27, 2026 at 1:50 am

    Use keys:

    <xsl:key name="en" match="translations/entry" use="@en"/>
    <xsl:key name="de" match="translations/entry" use="@de"/>
    <xsl:key name="fr" match="translations/entry" use="@fr"/>
    

    and then

      <xsl:template match="@name">
        <xsl:attribute name="name" select="key($pFrom, current(), $translatations)/@*[local-name() = $pTo]"/>
      </xsl:template>
    

    (I assume you use XSLT 2.0).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just got an answer to my question about combining the result of
Very basic question - but I couldn't find an answer. I have got a
I have got the following code from here to read an Excel file using
I posted a question here last week about using Ajax with J2EE and got
Following up from my last question @ stackoverflow.com/questions/7049245/ I got a couple of answers
Although I have been programming for about 11 years(mostly VB6, last 6 months C#),
I have asked a similar question before and while the answers I got were
I have got a question on regular expression. Though simple, I got some contracting
I previously asked the question and got answer to Best approach to write query
I asked this question a while ago and got an answer that I thought

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.