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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:27:39+00:00 2026-05-31T11:27:39+00:00

I have the structure: <root> <relation type=relation1> <entityType1>a</entityType1> <entityType2>1</entityType2> <entityType2>2</entityType2> <entityType2>3</entityType2> </relation> <relation type=relation2>

  • 0

I have the structure:

<root>
    <relation type="relation1">
        <entityType1>a</entityType1>
        <entityType2>1</entityType2>
        <entityType2>2</entityType2>
        <entityType2>3</entityType2>
    </relation>

    <relation type="relation2">
        <entityType3>b</entityType3>
        <entityType4>7</entityType4>
        <entityType4>8</entityType4>
        <entityType4>9</entityType4>
    </relation>

    <relation type="relation3">
        <entityType5>c</entityType3>
        <entityType6>10</entityType4>
        <entityType6>11</entityType4>
        <entityType6>12</entityType4>
    </relation>
</root>

I need to transform via XSLT to a HTML table that contains:

<table>
    <tr class="odd"><td>
        a --> 1
    </td></tr>

    <tr><td>
        a --> 2
    </td></tr>

    <tr class="odd"><td>
        a --> 3
    </td></tr>

    <tr><td>
        b --> 7
    </td></tr>

    <tr class="odd"><td>
        b --> 8
    </td></tr>

    <tr><td>
        b --> 9
    </td></tr>

    <tr class="odd"><td>
        c --> 10
    </td></tr>

    <tr><td>
        c --> 11
    </td></tr>

    <tr class="odd"><td>
        c --> 12
    </td></tr>
</table>

Please note the odd/even alternations of the table’s rows. I need to encode those as well via XSLT. Possible?

The basic question is actually how can I keep an index variable to indicate if the current row is odd or even while parsing this structure.
This would be enough to solve this because I currently have a … for the 2 relation types and then I iterate via a for-each over relation1/entityType2 and another for for-each over relation2/entityType4.

Thank you!

UPDATE-1:

Please note that the resulting table iterates through both relation1 and relation2 XML elements and it must somehow keep a global index that runs among both type of relations to correctly set the odd/even class when finishing the relation1 iteration and passing to relation2.

UPDATE-2:

Currently I have a code similar to this but I don’t know how to easily refactor it to handle the class=”odd” setting on tr. The templates Display_Relation currently display the text for relations.

<xsl:template match="relation">
        <xsl:choose>
            <xsl:when test="contains(@xsi:type, 'relation1')">
                <xsl:for-each select="entityType2">
                    <tr><td>
                        <xsl:call-template name="Display_Relation1">
                            <xsl:with-param name="source" select="../entityType1/text()"/>
                            <xsl:with-param name="destination" select="./text()"/>
                        </xsl:call-template>
                    </td></tr>
                </xsl:for-each>
            </xsl:when>

            <xsl:when test="contains(@xsi:type, 'relation2')">
                <xsl:for-each select="entityType4">
                    <tr><td>
                        <xsl:call-template name="Display_Relation2">
                            <xsl:with-param name="source" select="../entityType3/text()"/>
                            <xsl:with-param name="destination" select="./text()"/>
                        </xsl:call-template>
                    </td></tr>
                </xsl:for-each>
            </xsl:when>

            <xsl:when test="contains(@xsi:type, 'relation3')">
                <xsl:for-each select="entityType6">
                    <tr><td>
                        <xsl:call-template name="Display_Relation3">
                            <xsl:with-param name="source" select="../entityType5/text()"/>
                            <xsl:with-param name="destination" select="./text()"/>
                        </xsl:call-template>
                    </td></tr>
                </xsl:for-each>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
  • 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-31T11:27:40+00:00Added an answer on May 31, 2026 at 11:27 am

    Try something like this…

    <tr>
      <xsl:if test="boolean((count(preceding::*[parent::relation]) + 1) mod 2)">
        <xsl:attribute name="class">odd</xsl:attribute>
      </xsl:if>
      <xsl:apply-templates/>
    </tr>
    

    This assumes that the current context is *[parent::relation] (entityType1, entityType2, etc.), however the key piece is the use of the preceding:: axis.

    If you wanted, you could also use something like preceding::*[starts-with(name(),'entityType')] instead of preceding::*[parent::relation].

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

Sidebar

Related Questions

I have directory structure like so: |-- ROOT |-- Project1 | |-- application |
My folder structure is like - root admin create_page.php pages my_page1.php my_page2.php I have
I have a structure like this.... UITableViewController -> UITableViewCell -> UIView I need the
I have such singleton structure: // Hpp class Root : public boost::noncopyable { public:
I have the following directory structure (root) / | \ bin resources src |
I have this structure: <root> <properties> <property name=test> <value>X</value> </property> </properties> <things> <thing> <properties>
I have this directory structure: root: +pages -base.html ... +en -index.html ... index.py ...
I have an .Net MVC 3 web application that has the following structure root
I have following project structure -root -app.html -scripts/ -jquery/ locales.js -_locales/ -en/ -messages.json in
I am a newbie in this department.I have following folder structure root root\html root\html\html

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.