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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:39:55+00:00 2026-05-26T04:39:55+00:00

I have block of data sample in XML. Each data has a attribute called

  • 0

I have block of data sample in XML. Each data has a attribute called “switch” specifying if a switch is off or on ( default value is off ).
The goal is to add this information thanks to XSLT as an attribute of the block. This new atttribute “action” specifies whether the switch was turned off or on within the data block.

Case 1:

<block>
    <data switch="true">2.4</data>  
    <data switch="true">2.4</data>
    <data>270.0</data>
    <data>244.79999999999998</data>
    <data>330.59999999999997</data>
</block>

transformed in

<block action="turnedOFF">
    <data switch="true">2.4</data>
    <data switch="true">2.4</data>
    <data>270.0</data>
    <data>244.79999999999998</data>
    <data>330.59999999999997</data>
</block>

Case 2: Reversely, the xml below:

<block>
    <data>270.0</data>
    <data>244.79999999999998</data>
    <data>330.59999999999997</data>
    <data switch="true">2.4</data>
    <data switch="true">2.4</data>
</block>

is to be transformed into:

<block action="turnedON">
    <data>270.0</data>
    <data>244.79999999999998</data>
    <data>330.59999999999997</data>
    <data switch="true">2.4</data>
    <data switch="true">2.4</data>
</block>
  • 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-26T04:39:55+00:00Added an answer on May 26, 2026 at 4:39 am

    If you know there can be at most one transition of the switch attribute in the <data> elements, it should be enough to check the values of the first and last <data> element in a <block>. Here’s an untested attempt:

    <?xml version="1.0" encoding="utf-8"?>
    

    <xsl:template match="block">
        <block>
            <xsl:if test="data[1]/@switch and not(data[last()]/@switch)">
                <xsl:attribute name="action">turnedOFF</xsl:attribute>
            </xsl:if>
            <xsl:if test="not(data[1]/@switch) and data[last()]/@switch">
                <xsl:attribute name="action">turnedON</xsl:attribute>
            </xsl:if>
            <xsl:apply-templates select="@*|node()" />
        </block>
    </xsl:template>
    
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    

    Update
    I fixed a few errors and verified the transform. This works.

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

Sidebar

Related Questions

I have a block of binary data defined as: void* address, size_t binarySize; that
I have a function which takes a block of data and the size of
I have a custom image file where the first block of data is ASCII
I have just started using the Data Access Application Block from microsoft. There are
I have a javascript/jQuery block as a callback after $.get function: function myCallBack(data, textStatus)
I have a block of product images we received from a customer. Each product
I have the following (sample)code to filter search results from a LLBLGen data source:
i have to parse data xml. any one suggest me a simple parser so
I have an XML file with certain data which I have to convert it
I need to visualize some data. It's basic 2D grid, where each cell have

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.