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 7858941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:41:37+00:00 2026-06-02T21:41:37+00:00

A slightly different requirement to this question The dictionary stays the same format but

  • 0

A slightly different requirement to this question

The dictionary stays the same format but grows:

<resources>
    <text name="property.to.match">
        <en_US>The American translation</en_US>
        <en_GB>The British translation</en_GB>
        <en>The language localized, but non locale based generic translation</en>
    </text>
    <text name="other.property.to.match">
        <en>The other language localized, but non locale based generic translation</en>
    </text
    <text name="another.property.to.match">
        <en>Second generic property</en>
    </text>
    <text name="a.label.to.match">
        <en>Generic Checkbox label</en>
    </text>
    <text name="some.text.to.translate">
        <en>This text follows a static bit of text</en>
    </text>
</resources>

But the document in which I would like to match is more complex:

<html>
    <div>Lot's of html</div>
    <div>[property.to.match]</div>
    <div>
        <h1>[other.property.to.match]</h1>
        <p><img src="x.jpg" />[another.property.to.match]</p>
        <input type="checkbox"/>[a.label.to.match]
        <p>Some text that shouldn't be translated followed by [some.text.to.translate]
    </div>
</html>

So the matcher needs to be able to find multiple text strings within the */text() that start and end with [] but could be in amongst other nodes and bits of untrnaslated text.

Thanks again

  • 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-06-02T21:41:39+00:00Added an answer on June 2, 2026 at 9:41 pm

    This XSLT 1.0 transformation:

    <xsl:stylesheet version="1.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="pLookupPath" select="'file:///c:/temp/delete/lookup2.xml'"/>
         <xsl:param name="pLang" select="'en_GB'"/>
    
         <xsl:key name="kLookup" match="text/*"
          use="concat(../@name, '+', name())"/>
    
         <xsl:variable name="vDict" select="document($pLookupPath)"/>
    
         <xsl:template match="node()|@*">
             <xsl:copy>
               <xsl:apply-templates select="node()|@*"/>
             </xsl:copy>
         </xsl:template>
    
         <xsl:template name="replaceWithLookup" match=
          "text()[contains(., '[') and contains(., ']')]">
          <xsl:param name="pText" select="."/>
    
          <xsl:if test="string-length($pText)">
              <xsl:value-of select=
               "substring-before(concat($pText, '['), '[')"/>
    
              <xsl:variable name="vToken" select=
               "substring-before(substring-after($pText, '['), ']')"/>
    
            <xsl:variable name="vReplacement">
             <xsl:for-each select="$vDict">
              <xsl:value-of select=
              "(key('kLookup', concat($vToken, '+', $pLang))
             |
               key('kLookup', concat($vToken, '+', substring-before($pLang, '_')))
               )[1]"/>
             </xsl:for-each>
            </xsl:variable>
    
            <xsl:choose>
             <xsl:when test="$vReplacement">
              <xsl:value-of select="$vReplacement"/>
             </xsl:when>
             <xsl:when test="$vToken">
              <xsl:value-of select="concat('[', $vToken, ']')"/>
             </xsl:when>
             <xsl:otherwise>
               <xsl:value-of select=
                "substring-after
                  ($pText,
                   substring-before(concat($pText, '['), '[')
                   )"/>
             </xsl:otherwise>
            </xsl:choose>
    
            <xsl:if test="$vToken">
             <xsl:call-template name="replaceWithLookup">
               <xsl:with-param name="pText" select=
                "substring-after($pText, concat('[', $vToken, ']'))"/>
             </xsl:call-template>
            </xsl:if>
          </xsl:if>
         </xsl:template>
    </xsl:stylesheet>
    

    when applied on the following XML document (based on the provided one but made more difficult and challenging — the last text nodes contains two replacement targets):

    <html>
        <div>Lot's of html</div>
        <div>[property.to.match]</div>
        <div>
            <h1>[other.property.to.match]</h1>
            <p>
                <img src="x.jpg" />[another.property.to.match]
            </p>
            <input type="checkbox"/>[a.label.to.match]         
            <p>Some text that shouldn't be translated followed
            by [some.text.to.translate]
            XXX [other.property.to.match]
            </p>
        </div>
    </html>
    

    produces the wanted, correct result:

    <html>
       <div>Lot's of html</div>
       <div>The British translation</div>
       <div>
          <h1>The other language localized, but non locale based generic translation</h1>
          <p><img src="x.jpg">Second generic property
          </p><input type="checkbox">Generic Checkbox label
          <p>Some text that shouldn't be translated followed
                    by This text follows a static bit of text
                    XXX The other language localized, but non locale based generic translation
    
          </p>
       </div>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question has been asked before ( link ) but I have slightly different
I know this question has been done but I have a slightly different twist
This question comes close to what I need, but my scenario is slightly different.
i know this has been asked here . But my question is slightly different.
My question is similar to this question, but as always is slightly different. I
Similar question here but this is slightly different... I have two tables that I
I had posted a similar question earlier - a slightly different requirement here. I
I believe this question is slightly different than similar ones asked on here before
I'm going to re-ask this question in a slightly different way. Say I have
This problem probably has been discussed, but this one is slightly different. I'm using

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.