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

  • Home
  • SEARCH
  • 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 859167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:38:34+00:00 2026-05-15T08:38:34+00:00

From this XML source : <?xml version=1.0 encoding=utf-8 ?> <ROOT> <STRUCT> <COL order=1 nodeName=FOO/BAR

  • 0

From this XML source :

<?xml version="1.0" encoding="utf-8" ?>
<ROOT>
  <STRUCT>
    <COL order="1" nodeName="FOO/BAR" colName="Foo Bar" />
    <COL order="2" nodeName="FIZZ" colName="Fizz" />
  </STRUCT>

  <DATASET>
    <DATA>
      <FIZZ>testFizz</FIZZ>
      <FOO>
        <BAR>testBar</BAR>
        <LIB>testLib</LIB>
      </FOO>
    </DATA>
    <DATA>
      <FIZZ>testFizz2</FIZZ>
      <FOO>
        <BAR>testBar2</BAR>
        <LIB>testLib2</LIB>
      </FOO>
    </DATA>
  </DATASET>
</ROOT>

I want to generate this HTML :

<html>
  <head>
    <title>Test</title>
  </head>
  <body>
    <table border="1">
      <tr>
        <td>Foo Bar</td>
        <td>Fizz</td>
      </tr>
      <tr>
        <td>testBar</td>
        <td>testFizz</td>
      </tr>
      <tr>
        <td>testBar2</td>
        <td>testFizz2</td>
      </tr>
    </table>
  </body>
</html>

Here is the XSLT I currently have :

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:output method="html" indent="yes"/>

  <xsl:template match="/ROOT">
    <html>
      <head>
        <title>Test</title>
      </head>
      <body>
        <table border="1">
          <tr>
            <!--Generate the table header-->
            <xsl:apply-templates select="STRUCT/COL">
              <xsl:sort data-type="number" select="@order"/>
            </xsl:apply-templates>
          </tr>
          <xsl:apply-templates select="DATASET/DATA" />
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="COL">
    <!--Template for generating the table header-->
    <td>
      <xsl:value-of select="@colName"/>
    </td>
  </xsl:template>

  <xsl:template match="DATA">
    <xsl:variable name="pos" select="position()" />
    <tr>
      <xsl:for-each select="/ROOT/STRUCT/COL">
        <xsl:sort data-type="number" select="@order"/>
        <xsl:variable name="elementName" select="@nodeName" />
        <td>
          <xsl:value-of select="/ROOT/DATASET/DATA[$pos]/*[name() = $elementName]" />
        </td>
      </xsl:for-each>
    </tr>
  </xsl:template>

</xsl:stylesheet>

It almost works, the problem I have is to retrieve the correct DATA node from the path specified in the “nodeName” attribute value of the STRUCT 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-15T08:38:35+00:00Added an answer on May 15, 2026 at 8:38 am

    Here is a pure XSLT 1.0 solution that doesn’t use any extensions:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:template match="/">
      <html>
        <head>
          <title>Test</title>
        </head>
        <body>
          <table border="1">
            <xsl:apply-templates select="*/STRUCT"/>
            <xsl:apply-templates select="*/DATASET/DATA"/>
          </table>
        </body>
      </html>
     </xsl:template>
    
     <xsl:template match="STRUCT">
      <tr>
        <xsl:apply-templates select="COL"/>
      </tr>
     </xsl:template>
    
     <xsl:template match="COL">
      <td><xsl:value-of select="@colName"/></td>
     </xsl:template>
    
     <xsl:template match="DATA">
          <tr>
            <xsl:apply-templates select="/*/STRUCT/*/@nodeName">
             <xsl:with-param name="pCurrentNode" select="."/>
            </xsl:apply-templates>
          </tr>
     </xsl:template>
    
     <xsl:template match="@nodeName" name="getNodeValue">
       <xsl:param name="pExpression" select="string(.)"/>
       <xsl:param name="pCurrentNode"/>
    
       <xsl:choose>
        <xsl:when test="not(contains($pExpression, '/'))">
          <td><xsl:value-of select="$pCurrentNode/*[name()=$pExpression]"/></td>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="getNodeValue">
            <xsl:with-param name="pExpression"
              select="substring-after($pExpression, '/')"/>
            <xsl:with-param name="pCurrentNode" select=
            "$pCurrentNode/*[name()=substring-before($pExpression, '/')]"/>
          </xsl:call-template>
        </xsl:otherwise>
       </xsl:choose>
    
     </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on the provided XML document:

    <ROOT>
      <STRUCT>
        <COL order="1" nodeName="FOO/BAR" colName="Foo Bar" />
        <COL order="2" nodeName="FIZZ" colName="Fizz" />
      </STRUCT>
    
      <DATASET>
        <DATA>
          <FIZZ>testFizz</FIZZ>
          <FOO>
            <BAR>testBar</BAR>
            <LIB>testLib</LIB>
          </FOO>
        </DATA>
        <DATA>
          <FIZZ>testFizz2</FIZZ>
          <FOO>
            <BAR>testBar2</BAR>
            <LIB>testLib2</LIB>
          </FOO>
        </DATA>
      </DATASET>
    </ROOT>
    

    the wanted, correct result is produced:

    <html>
        <head>
            <title>Test</title>
        </head>
        <body>
            <table border="1">
                <tr>
                    <td>Foo Bar</td>
                    <td>Fizz</td>
                </tr>
                <tr>
                    <td>testBar</td>
                    <td>testFizz</td>
                </tr>
                <tr>
                    <td>testBar2</td>
                    <td>testFizz2</td>
                </tr>
            </table>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 523k
  • Answers 523k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is really a CSS quetion. z-index only takes affect… May 16, 2026 at 9:46 pm
  • Editorial Team
    Editorial Team added an answer From itertools examples: from itertools import tee, filterfalse def partition(pred,… May 16, 2026 at 9:46 pm
  • Editorial Team
    Editorial Team added an answer You will need to use the DIA SDK. Microsoft does… May 16, 2026 at 9:46 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Currently, I have this version of the autocomplete control working when returning XML from
I have a class that unmarshals xml from a 3rd party source (I have
I have this open-source library that I'm having some trouble fixing a problem... This
I'm building a python application from some source code I've found Here I've managed
this is a follow up question from this one , I don't want to
This is part of one of our XML files in SharePoint: <BuildManifest nsprefix =ns0
I was reading about data driven testing using mbunit from this article. http://blog.benhall.me.uk/2007/04/mbunit-datafixture-data-driven-unit.html I
I am stuck with something quite simple but really annoying: I have an xml
I try many different solution on this site and none seems to work for
I'm trying to generate beans from an xsd by using the jaxb2-maven-plugin maven plugin,

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.