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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:05:44+00:00 2026-05-16T18:05:44+00:00

I’m trying to add different tags to a node depending on an attribute value

  • 0

I’m trying to add different tags to a node depending on an attribute value of its grandchild node.

Sample Input (a 1×3 table):

<table>
    <row>
        <cell row="1" column="1" >heading text one</cell>
    </row>

    <row>
        <cell row="2" column="1" >body text one</cell>
    </row>
    <row>
        <cell row="3" column="1" >body text two</cell>
    </row>
</table>

Need output like this:

<TableElmt>
    <HeadingElmt>
        <RowElmt>
            <CellElmt>heading text one</CellElmt>
        </RowElmt>
    </HeadingElmt>

    <BodyElmt>
        <RowElmt>
            <CellElmt>body text one</CellElmt>
        </RowElmt>
        <RowElmt>
            <CellElmt>body text two</CellElmt>
        </RowElmt>
    </BodyElmt>
</TableElmt>

Basically I can only decide if the row is a heading row based on the @row element of the cell.

Here’s what I’ve tried:

<xsl:template name="matcheverything" match="table">
    <xsl:apply-templates select="row" />
</xsl:template>

<xsl:template name="matchheadings" match="table[*/*/@row=1]">
    <BodyElmt>
        <xsl:apply-templates select="row" />
    </BodyElmt>
</xsl:template>

<xsl:template match="row">
    <xsl:choose>
        <xsl:when test="*/@row=1">
            <HeadingElmt><RowElmt>
                <xsl:apply-templates select="cell"/>
            </RowElmt></HeadingElmt>
        </xsl:when>
        <xsl:otherwise>
            <RowElmt>
                <xsl:apply-templates select="cell"/>
            </RowElmt>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template match="cell">
    <CellElmt><xsl:apply-templates select="*"/></CellElmt>
</xsl:template>

I was thinking the “matchheadings” template, having a more specific match requirement, should recognize the heading row, however it’s actually matching every single row in the table.

So my actual out put from this stylesheet is every row treated as a heading row – very bad 🙁

<TableElmt>
    <HeadingElmt>
        <RowElmt>
            <CellElmt>heading text one</CellElmt>
        </RowElmt>

        <RowElmt>
            <CellElmt>body text one</CellElmt>
        </RowElmt>
        <RowElmt>
            <CellElmt>body text two</CellElmt>
        </RowElmt>
    </HeadingElmt>
</TableElmt>
  • 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-16T18:05:44+00:00Added an answer on May 16, 2026 at 6:05 pm

    This 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:template match="table">
      <TableElmt>
       <xsl:apply-templates/>
      </TableElmt>
     </xsl:template>
    
     <xsl:template match="row[cell/@row='1']">
      <HeadingElmt>
       <xsl:apply-templates select="." mode="copy"/>
      </HeadingElmt>
     </xsl:template>
    
     <xsl:template match="row[cell[not(@row='1')]][1]">
      <BodyElmt>
       <xsl:apply-templates select=".|following-sibling::row" mode="copy"/>
      </BodyElmt>
     </xsl:template>
    
     <xsl:template match="row" mode="copy">
       <RowElmt>
         <xsl:apply-templates/>
       </RowElmt>
     </xsl:template>
    
     <xsl:template match="cell">
       <CellElmt>
        <xsl:value-of select="."/>
       </CellElmt>
     </xsl:template>
    
     <xsl:template match="row"/>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <table>
        <row>
            <cell row="1" column="1" >heading text one</cell>
        </row>
        <row>
            <cell row="2" column="1" >body text one</cell>
        </row>
        <row>
            <cell row="3" column="1" >body text two</cell>
        </row>
    </table>
    

    produces the wanted, correct result:

    <TableElmt>
        <HeadingElmt>
            <RowElmt>
                <CellElmt>heading text one</CellElmt>
            </RowElmt>
        </HeadingElmt>
        <BodyElmt>
            <RowElmt>
                <CellElmt>body text one</CellElmt>
            </RowElmt>
            <RowElmt>
                <CellElmt>body text two</CellElmt>
            </RowElmt>
        </BodyElmt>
    </TableElmt>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to select an H1 element which is the second-child in its group
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I need to clean up various Word 'smart' characters in user input, including but

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.