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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:26:08+00:00 2026-06-14T13:26:08+00:00

Is it possible to have a better solution for the following: Input xml <product>

  • 0

Is it possible to have a better solution for the following:

Input xml

<product>

<text>
<languageId>en-us</languageId>
<description>some text en us</description>
</text>

<text>
<languageId>en-gb</languageId>
<description>some text en gb</description>
</text>

<text>
<languageId>en-us</languageId>
</text>

<product>

Output xml

<specifications>some text en us</specifications>

So, if there is a description with languageId = en-us and there is text present, then this text will be placed in the output xml, otherwise the element receives the attribute value xsi:nil=true

xslt version must be 1.0

XSLT

 <ns0:specifications>

          <!-- First loop, check if en-us is present, if so, check if there is a text! -->
          <!-- If the 2 requirements are met, then this Txt element is used -->
          <xsl:for-each select="s0:text">
            <xsl:if test="translate(s0:LanguageId/text(),$smallcase,$uppercase)=translate('en-us',$smallcase,$uppercase)">
              <xsl:if test="s0:Txt!=''">
                <xsl:value-of select="s0:Txt/text()" />
              </xsl:if>
            </xsl:if>
          </xsl:for-each>

        <!-- Second loop, checks are the same. This loop is needed because xsl variables are immutable. If there is a better solution, just change the code!! -->
        <!-- If the 2 requirements are met, then the variable is marked as true, else it's empty -->
        <xsl:variable name="isEnUsPresent">
          <xsl:for-each select="s0:text">
            <xsl:if test="translate(s0:LanguageId/text(),$smallcase,$uppercase)=translate('en-us',$smallcase,$uppercase)">
              <xsl:if test="s0:Txt!=''">
                <xsl:value-of select="1" />
              </xsl:if>
            </xsl:if>
          </xsl:for-each>
        </xsl:variable>

        <!-- if the variable is empty, set the attribute value xsi:nil=true like below -->
        <xsl:choose>
          <xsl:when test="$isEnUsPresent=''">
            <xsl:attribute name="xsi:nil">
              <xsl:value-of select="'true'" />
            </xsl:attribute>
          </xsl:when>
        </xsl:choose>

</ns0:specifications> 

Regards

  • 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-14T13:26:10+00:00Added an answer on June 14, 2026 at 1:26 pm

    As simple as this:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     exclude-result-prefixes="xsi">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="/">
         <specifications>
          <xsl:apply-templates select="*"/>
         </specifications>
     </xsl:template>    
    
     <xsl:template match="text[languageId='en-us']/description">
      <xsl:value-of select="."/>
     </xsl:template>
    
     <xsl:template match="/*[not(text[languageId='en-us']/description)]">
      <xsl:attribute name="xsi:nil">true</xsl:attribute>
     </xsl:template>
     <xsl:template match="text()"/>
    </xsl:stylesheet>
    

    When this transformation is applied on the provided XML document:

    <product>
        <text>
            <languageId>en-us</languageId>
            <description>some text en us</description>
        </text>
        <text>
            <languageId>en-gb</languageId>
            <description>some text en gb</description>
        </text>
        <text>
            <languageId>en-us</languageId>
        </text>
    </product>
    

    the wanted, correct result is produced:

    <specifications>some text en us</specifications>
    

    When the same transformation is applied to this XML document:

    <product>
        <text>
            <languageId>en-us-XXX</languageId>
            <description>some text en us</description>
        </text>
        <text>
            <languageId>en-gb</languageId>
            <description>some text en gb</description>
        </text>
        <text>
            <languageId>en-us</languageId>
        </text>
    </product>
    

    again the wanted, correct result is produced:

    <specifications xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: A better way to compare Strings which could be null I have
Lets say I have the following code: public class Base { // Some stuff
Possible Duplicate: how to provide a swap function for my class? There are some
I have a XML file similar to the following: <a> <b value=a123 /> <b
I was wondering if the following structure is possible. Here I have a div
I need to do the following: I have 2 input pins on a microcontroller,
We have an ordered list <ol> <li>something good</li> <li>even better</li> <li>possibly the best</li> </ol>
Is it possible have two projects with the same name in flex builder? Here
is possible to have a separator between elements of a GridView? Thanks
Is it possible to have a many to many relationship between two tables, and

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.