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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:50:00+00:00 2026-05-12T06:50:00+00:00

We have xml documents that contain lots of flagged nodes like isProduct, isActive ,

  • 0

We have xml documents that contain lots of flagged nodes like isProduct, isActive , isMandatory where the node text may be True or False.

It is needed to manipulate the documents and keep their structure but convert the above nodes into a verbal representation like below:

< isProduct >True</ isProduct >   ===>   <Type>Product<Type>
< isProduct >False</ isProduct >  ===>   <Type/>

And the same for other flag nodes.

We are seeking an extensible and scalable solution that can be configured with minimum friction after deployment.

By extensible; we mean that there will be more cases; like 2 flags that represent a status; i.e. isEmployee and isCustomer is used in the document to represent 4 different named things.; hence the 4 possible combinations should only be translate into one string like “Employee”, “Customer”, “Customer-Employee” or “None”.

By scalable; we mean that it can be used to process any XML document without a prior understanding of its schema and no restriction on the document size.

We do understand that this might be done using XSLT, can we write an XSLT that an accept any document and produce the same document with additional nodes added or update?

  • 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-12T06:50:00+00:00Added an answer on May 12, 2026 at 6:50 am

    Assuming an input like this:

    <gizmo>
      <isProduct>True</isProduct>
      <isFoo>False</isFoo>
      <isBar>True</isBar>
    </gizmo>
    

    The generic approach would be:

    <xsl:template match="gizmo">
      <xsl:copy>
        <xsl:apply-templates select="*" />
      </xsl:copy>
    </xsl:template>
    
    <xsl:template match="*[substring(local-name(), 1, 2) = 'is']">
      <Type>
        <xsl:if test=". = 'True'">
          <xsl:value-of select="substring-after(local-name(), 'is')" />
        </xsl:if>
      </Type>
    </xsl:template>
    

    Which produces:

    <gizmo>
      <Type>Product</Type>
      <Type />
      <Type>Bar</Type>
    </gizmo>
    

    An even more generalized approach uses a (heavily) modified identity transform:

    <!-- the identity template... well, sort of -->
    <xsl:template match="node() | @*">
      <xsl:copy>
        <!-- all element-type children that begin with 'is' -->
        <xsl:variable name="typeNodes"  select="
          *[substring(local-name(), 1, 2) = 'is']
        " />
    
        <!-- all other children (incl. elements that don't begin with 'this ' -->
        <xsl:variable name="otherNodes" select="
          @* | node()[not(self::*) or self::*[substring(local-name(), 1, 2) != 'is']]
        " />
    
        <!-- identity transform all the "other" nodes -->
        <xsl:apply-templates select="$otherNodes" />
    
        <!-- collapse all the "type" nodes into a string -->
        <xsl:if test="$typeNodes">
          <Type>
            <xsl:variable name="typeString">
              <xsl:apply-templates select="$typeNodes" />
            </xsl:variable>
            <xsl:value-of select="substring-after($typeString, '-')" />
          </Type>
        </xsl:if>
      </xsl:copy>
    </xsl:template>
    
    <!-- this collapses all the "type" nodes into a string -->
    <xsl:template match="*[substring(local-name(), 1, 2) = 'is']">
      <xsl:if test=". = 'True'">
        <xsl:text>-</xsl:text>
        <xsl:value-of select="substring-after(local-name(), 'is')" />
      </xsl:if>
    </xsl:template>
    
    <!-- prevent the output of empty text nodes -->
    <xsl:template match="text()">
      <xsl:if test="normalize-space() != ''">
        <xsl:value-of select="." />
      </xsl:if>
    </xsl:template>
    

    The above takes any XML input whatsoever and outputs the same structure, only elements named <is*> are collapsed into a single <Type> node as a dash-delimited string:

    <!-- in -->
    <foo>
      <fancyNode />
      <gizmo>
        <isProduct>True</isProduct>
        <isFoo>False</isFoo>
        <isBar>True</isBar>
      </gizmo>
    </foo>
    
    <!-- out -->
    <foo>
      <fancyNode />
      <gizmo>
        <Type>Product-Bar</Type>
      </gizmo>
    </foo>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often have to deal with XML documents that contain namespaced elements, but doesn't
I have some word templates(dot/dotx) files that contain xml tags along with plain text.
I have 2 Document objects with documents that contain similiar XML's. For example: <tt:root
I have a number rather large, complex xml documents that I need to loop
I have an xml document that looks like this. <foo> <bar type=artist/> Bob Marley
I have an XML document that matches our site navigation something like this: <page
I have xml which contain some documents: <document> <line id=0> <field id=0><![CDATA[H:doc1]]></field> </line> <line
I have a xml document which has a node that contains a proper name
I have an XML document that I'm trying to search through. The Main structure
I have an XML document that I generate from an Entity Framework object. The

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.