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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:54:06+00:00 2026-06-04T20:54:06+00:00

I am working on the XSLT. Depending upon the values in the table I

  • 0

I am working on the XSLT.

Depending upon the values in the table I have to write the  XML file.

Rules:

1.If the values in columns of I row are in strong(Enclosed in<strong> tags).
  Then I have to add attribute as "FirstRowIsStrong".

2.If all the values in the I column are in strong. 
   Then I have to add attribute as "FirstCoulmnIsStrong".

3.If the values in any row are in Strong, 
    then I have to add attribute as  "RowIsStrong". 
    If its the first row I need not add attribute.
    If the values in First row are in strong I should not add attribute.
    For the rows other than First row, I have to add the attribute.

I have source XML like this.

        <table style="WIDTH: 100%" border="1" cellspacing="1" cellpadding="1">

        <tr>
        <td><strong xmlns="http://www.w3.org/1999/xhtml">A</strong></td>
        <td><strong xmlns="http://www.w3.org/1999/xhtml">B</strong></td>
        <td><strong xmlns="http://www.w3.org/1999/xhtml">C</strong></td>
        </tr>
        <tr>
        <td><strong xmlns="http://www.w3.org/1999/xhtml">D</strong></td>
        <td>E</td>
        <td>F</td>
        </tr>
        <tr>
        <td><strong xmlns="http://www.w3.org/1999/xhtml">G</strong></td>
        <td><strong xmlns="http://www.w3.org/1999/xhtml">H</strong></td>
        <td><strong xmlns="http://www.w3.org/1999/xhtml">I</strong></td>
        </tr>
        <tr>
        <td><strong xmlns="http://www.w3.org/1999/xhtml">J</strong></td>
        <td>K</td>
        <td>L</td>
        </tr>

        </table>

I should have the output as

<tabledata FirstRowIsStrong="true" FirstCoulmnIsStrong="true">
    <row>
        <column>A</column>
        <column>B</column>
        <column>C</column>          
    </row>
    <row>
        <column>D</column>
        <column>E</column>
        <column>F</column>          
    </row>
    <row RowIsStrong="true">
        <column>G</column>
        <column>H</column>
        <column>I</column>          
    </row>
    <row>
        <column>J</column>
        <column>K</column>
        <column>L</column>          
    </row>
  </tabledata>

I could able to get the values, but I am not sure how to add the attributes as per the requirement.

Can any one help me out how it can be done.

Thank you.

  • 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-04T20:54:09+00:00Added an answer on June 4, 2026 at 8:54 pm

    For the FirstRowIsStrong you need a test to check there the first row does not contain a td element which has no strong element

    <xsl:if test="tr[1][not(td[not(xhtml:strong)])]">
    

    Similary, for the FirstColumnIsStrong you need a test to check there is no row first a first cell that does not contain a strong element

    <xsl:if test="not(tr[td[1][not(xhtml:strong)]])">
    

    And for the RowIsStrong you can use a template match to check the non-first row does not contain any such td elements

    <xsl:template match="tr[position() != 1][not(td[not(xhtml:strong)])]">
    

    Here is the full XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xhtml">
       <xsl:output method="xml" indent="yes"/>
    
       <xsl:template match="table">
          <tabledata>
             <xsl:if test="tr[1][not(td[not(xhtml:strong)])]">
                <xsl:attribute name="FirstRowIsStrong">true</xsl:attribute>
             </xsl:if>
             <xsl:if test="not(tr[td[1][not(xhtml:strong)]])">
                <xsl:attribute name="FirstColumnIsStrong">true</xsl:attribute>
             </xsl:if>
             <xsl:apply-templates select="@*|node()"/>
          </tabledata>
       </xsl:template>
    
       <xsl:template match="tr[position() != 1][not(td[not(xhtml:strong)])]">
          <row RowIsStrong="true">
             <xsl:apply-templates select="@*|node()"/>
          </row>
       </xsl:template>
    
       <xsl:template match="tr">
          <row>
             <xsl:apply-templates select="@*|node()"/>
          </row>
       </xsl:template>
    
       <xsl:template match="td">
          <column>
             <xsl:apply-templates select="@*|node()"/>
          </column>
       </xsl:template>
    
       <xsl:template match="xhtml:strong">
          <strong>
             <xsl:apply-templates select="@*|node()"/>
          </strong>
       </xsl:template>
    
       <xsl:template match="@*|node()">
          <xsl:copy>
             <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your input XML, the following is output

    <tabledata FirstRowIsStrong="true" FirstColumnIsStrong="true" style="WIDTH: 100%" border="1" cellspacing="1" cellpadding="1">
       <row>
          <column>
             <strong>A</strong>
          </column>
          <column>
             <strong>B</strong>
          </column>
          <column>
             <strong>C</strong>
          </column>
       </row>
       <row>
          <column>
             <strong>D</strong>
          </column>
          <column>E</column>
          <column>F</column>
       </row>
       <row RowIsStrong="true">
          <column>
             <strong>G</strong>
          </column>
          <column>
             <strong>H</strong>
          </column>
          <column>
             <strong>I</strong>
          </column>
       </row>
       <row>
          <column>
             <strong>J</strong>
          </column>
          <column>K</column>
          <column>L</column>
       </row>
    </tabledata>
    

    Do note the extra code to remove the namespace from the strong element

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

Sidebar

Related Questions

I'm working on XSLT. I have this XML source file : <?xml version=1.0 encoding=UTF-8?>
I'm working on an XSLT file to transform an XML doc that represents a
I have been working on a XSLT file here. I had been writing CSS
I'm working on a XSLT file and I've hit a snag. I have a
I am working on this from xslt cookbook type my.xml <?xml version=1.0 encoding=UTF-8?> <people>
i have the following xslt sheet: <?xml version=1.0 encoding=UTF-8 ?> <xsl:stylesheet xmlns:xsl=http://www.w3.org/1999/XSL/Transform version=1.0> <xsl:variable
I'm working on a XSLT transformation that consists on merging two XML and then
I have the following code that applies a XSLT style Test.Xml.xslTransform = function(xml, xsl)
I'm working on an application that uses XSLT to transform XML generated by JSP.
I am working under java application which uses XSLT transformation. I have a lot

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.