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

The Archive Base Latest Questions

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

My XML is shown below: <?xml version=1.0 encoding=UTF-8?> <JobListing> <ColumnOrder> <columnId>4</columnId> <columnId>2</columnId> <columnId>5</columnId> <columnId>1</columnId>

  • 0

My XML is shown below:

<?xml version="1.0" encoding="UTF-8"?>
<JobListing>
    <ColumnOrder>
        <columnId>4</columnId>
        <columnId>2</columnId>
        <columnId>5</columnId>
        <columnId>1</columnId>
        <columnId>3</columnId>
    </ColumnOrder>
    <Jobs>
        <Job>
            <title>Java Developer</title>
            <code>JAVA</code>
            <openings>10</openings>
            <location>USA</location>
            <duration>6 months</duration>
        </Job>
        <Job>
            <title>.NET Developer</title>
            <code>DOTNET</code>
            <openings>10</openings>
            <location>USA</location>
            <duration>6 months</duration>
        </Job>
    </Jobs>
</JobListing>

I’ve a specific requirement that Jobs should be listed in a HTML page based on ColumnOrder specified in the XML. Internally, each columnId is mapped to a column as given below:

  • 1 -> Title
  • 2 -> Code
  • 3 -> Openings
  • 4 -> Location
  • 5 -> Duration

In this case, for example, Job listing page should list columns in this order – Location, Code, Duration, Title, Openings. Am expecting something like as explained below:

<tr>
  loop jobs
     for each columnorder
              if(columnId == 1)
                        <td>get Title</td>
              else if (columnId == 2)
                        <td>get Code</td>
              else if (columnId == 3)
                        <td>get Openings</td>
              else if (columnId == 4)
                        <td>get Location</td>
              else if (columnId == 5)
                        <td>get Duration</td>
              end if
     end columnorder
  end jobs
</tr>   

How do I achieve this using XSLT?

Any help or different ideas/suggestions would be greatly appreciated.

EDIT: The <Job> elements in the XML (title, openings, location, duration, code) are not necessarily in the same order. In fact, in our current framework, it gets generated in ascending order (like code, duration, location, openings, title). How to make it work without taking into account order of elements of <Job>?

  • 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-25T20:31:39+00:00Added an answer on May 25, 2026 at 8:31 pm

    This transformation works even when the children of Job are mixed in any order:

        <xsl:stylesheet version="1.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         xmlns:my="my:my" exclude-result-prefixes="my">
         <xsl:output omit-xml-declaration="yes" indent="yes"/>
         <xsl:strip-space elements="*"/>
    
         <my:Mapping>
           <id val="1">title</id>
           <id val="2">code</id>
           <id val="3">openings</id>
           <id val="4">location</id>
           <id val="5">duration</id>
         </my:Mapping>
    
         <xsl:variable name="vOrder" select="/*/ColumnOrder/*"/>
    
         <xsl:variable name="vMap" select=
              "document('')/*/my:Mapping/*"/>
    
         <xsl:template match="Jobs">
             <table>
              <xsl:apply-templates/>
             </table>
         </xsl:template>
    
         <xsl:template match="Job">
          <tr>
           <xsl:apply-templates select="*">
             <xsl:sort data-type="number" select=
              "count($vOrder
                          [. = $vMap
                                  [. = name(current())]/@val
                          ]
                           /preceding-sibling::*
                     )
              "/>
           </xsl:apply-templates>
          </tr>
         </xsl:template>
    
         <xsl:template match="Job/*">
          <td><xsl:value-of select="."/></td>
         </xsl:template>
    
         <xsl:template match="ColumnOrder"/>
    </xsl:stylesheet>
    

    When applied on the provided XML document:

    <JobListing>
        <ColumnOrder>
            <columnId>4</columnId>
            <columnId>2</columnId>
            <columnId>5</columnId>
            <columnId>1</columnId>
            <columnId>3</columnId>
        </ColumnOrder>
        <Jobs>
            <Job>
                <title>Java Developer</title>
                <code>JAVA</code>
                <openings>10</openings>
                <location>USA</location>
                <duration>6 months</duration>
            </Job>
            <Job>
                <title>.NET Developer</title>
                <code>DOTNET</code>
                <openings>10</openings>
                <location>USA</location>
                <duration>6 months</duration>
            </Job>
        </Jobs>
    </JobListing>
    

    The wanted, correct result is produced:

    <table>
       <tr>
          <td>USA</td>
          <td>JAVA</td>
          <td>6 months</td>
          <td>Java Developer</td>
          <td>10</td>
       </tr>
       <tr>
          <td>USA</td>
          <td>DOTNET</td>
          <td>6 months</td>
          <td>.NET Developer</td>
          <td>10</td>
       </tr>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple XML file as shown below. <?xml version=1.0 encoding=UTF-8?> <myConfig> <datasets>
I have defined a xml schema as below <?xml version=1.0 encoding=utf-8?> <xs:schema id=PacketTemplate targetNamespace=http://tempuri.org/PacketTemplate.xsd
I have XML similar to the following <?xml version=1.0 encoding=utf-8?> <foo name=FooBar xmlns=http://mydomain/myapp/ver/myschema.xsd> <bars
Given the following XML: <?xml version=1.0 encoding=UTF-8?> <userAttributeList> <attribute> <userId>12345678</userId> <attId>1234</attId> <attName>Group</attName> <attTypeId>8</attTypeId> <attTypeName>User
<?xml version=1.0 encoding=UTF-8 standalone=yes?> <w:document xmlns:ve=http://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:o=urn:schemas-microsoft-com:office:office xmlns:r=http://schemas.openxmlformats.org/officeDocument/2006/relationships xmlns:m=http://schemas.openxmlformats.org/officeDocument/2006/math xmlns:v=urn:schemas-microsoft-com:vml xmlns:wp=http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing xmlns:w10=urn:schemas-microsoft-com:office:word xmlns:w=http://schemas.openxmlformats.org/wordprocessingml/2006/main xmlns:wne=http://schemas.microsoft.com/office/word/2006/wordml>
I created an XML file for an AppWidget as shown below. xml/appwidget_4x1.xml <?xml version=1.0
I have an XML document that looks like this: <?xml version=1.0 encoding=UTF-8?> <xs:msgdata xmlns:xs=http://www.myCompany.com
i have an xml file sitemap.xml as shown below ..i need to add one
I have a bit of xml file named Sample.xml which is shown below <?xml
I using a dataset to read an xml file as shown below DataSet ds

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.