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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:37:25+00:00 2026-06-06T14:37:25+00:00

I have been scouring the web for something like this and being a lazy

  • 0

I have been scouring the web for something like this and being a lazy programmer, before I attempt to do so myself, I thought I would ask here.

What I would like is a method to take any xml with node names following a convention (like cakephp or ruby) and then for that data to be presented in a ready to print format.

ie:

<xml>
<home_address>The Street</home_address>
</xml>

to:

<tr><td>Home Address</td><td>The Street</td></tr>

etc. with children having separate tables.

It seems pretty straightforward and something that would have been desired many times before. I found one useful discussion, but with no conclusion.

http://www.daniweb.com/software-development/xml-xslt-and-xpath/threads/363621/xml-to-html-using-xslt-without-hardcoding-node-names-in-xslt

Have I missed something here? Is there a simple generic xslt/css method for doing this? Or is this work being repeated hundreds of times a day in cubicles around the world?

Thanks in advance,

F

  • 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-06T14:37:25+00:00Added an answer on June 6, 2026 at 2:37 pm

    use the following XSL stylesheet. I have tested it and it works.

    <?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:template match="/">
        <xsl:for-each select="*">
          <xsl:for-each select="*">
            <tr>
              <xsl:variable name="NodeNameClearText">
                <xsl:call-template name="repalceNodeName">
                  <xsl:with-param name="value" select="local-name(.)"/>
                </xsl:call-template>
              </xsl:variable>
                  <td>
                    <xsl:value-of select="$NodeNameClearText" />
                  </td>
                  <td>
                    <xsl:value-of select="." />
                  </td>
                </tr>
          </xsl:for-each>
        </xsl:for-each>
      </xsl:template>
    
      <xsl:template name="repalceNodeName">
        <xsl:param name="value"/>
        <xsl:variable name="valueWithoutUnderscores">
          <xsl:value-of select="translate($value, '_',' ')"/>
        </xsl:variable>
        <xsl:call-template name="caseLowerAcceptFirstWord">
          <xsl:with-param name="data" select="$valueWithoutUnderscores"/>
        </xsl:call-template>
      </xsl:template>
    
      <xsl:template name="caseDown">
        <xsl:param name="data"/>
        <xsl:if test="$data">
          <xsl:choose>
            <xsl:when test="starts-with($data,' ')">
              <xsl:text> </xsl:text>
              <xsl:call-template name="caseLowerAcceptFirstWord">
                <xsl:with-param name="data" select="normalize-space(substring($data,2))"/>
              </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="translate(substring($data,1,1),
                                      'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>
              <!-- put all the chars you want to change 
                     into the last two strings -->
              <xsl:call-template name="caseDown">
                <xsl:with-param name="data" select="substring($data,2)"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:if>
      </xsl:template>
    
      <xsl:template name="caseUP">
        <xsl:param name="data"/>
        <xsl:if test="$data">
          <xsl:choose>
            <xsl:when test="starts-with($data,' ')">
              <xsl:text> </xsl:text>
              <xsl:call-template name="caseLowerAcceptFirstWord">
                <xsl:with-param name="data" select="substring($data,2)"/>
              </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="translate(substring($data,1,1),
                                      'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
              <!-- put all the chars you want to change 
                     into the last two strings -->
              <xsl:call-template name="caseDown">
                <xsl:with-param name="data" select="substring($data,2)"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:if>
      </xsl:template>
    
      <xsl:template name="caseLowerAcceptFirstWord">
        <xsl:param name="data"/>
        <xsl:variable name="upperData">
          <xsl:call-template name="caseUP">
            <xsl:with-param name="data" select="$data"/>
          </xsl:call-template>
        </xsl:variable>
        <xsl:if test="$upperData">
          <xsl:value-of select="substring($upperData,1,1)"/>
          <xsl:call-template name="caseDown">
            <xsl:with-param name="data" select="substring($data,2)"/>
          </xsl:call-template>
        </xsl:if>
      </xsl:template>
    </xsl:stylesheet>
    

    A little more info on what I tested. The following XML:

    <xml>
    <home_address>The Street</home_address>
    <po_box>474</po_box>
    </xml>
    

    Was output to

    <tr><td>Home Address</td><td>The Street</td></tr>
    <tr><td>Po Box</td><td>474</td></tr>
    

    If thats not what you wanted your question is to vague

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

Sidebar

Related Questions

I have been scouring the internet for a way to do this with no
I need some help I have been scouring the web and haven't been able
I have been scouring for a while about this one but haven't seen a
I have been scouring the web for how to solve my problem with grails
I've been scouring Google for an answer to this problem I'm having and have
I have been scouring the internet trying to figure this one out. Any ideas
I know this has been asked ALOT on here, but I have been scouring
Now I have been scouring the web for what seems to be a mystery
I have been scouring the web to try to find the perfect technique for
I have been scouring the web for a code sample that shows how to

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.