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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:38:35+00:00 2026-05-22T20:38:35+00:00

So I have a XML document generated by my application like this: <?xml version=1.0

  • 0

So I have a XML document generated by my application like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE AddressBook>
<?xml-stylesheet type="text/xsl" href="stylesheet.xsl"?>
<AddressBook>
 <Item>
  <UserGeneratedElementName1 class="info">Whatever blah blah</UserGeneratedElementName1>
  <UserGeneratedElementName2 class="info">Whatever blah blah</UserGeneratedElementName2>
 </Item>
 <Item>
  <UserGeneratedElementName3 class="info">Whatever blah blah</UserGeneratedElementName3>
 </Item>
 ...
 ...
 Other Items with user-generated elements with user-generated content...
</AddressBook>

And I want to turn it into a HTML document similar to this:

<html>
<head>
 <title>AddressBook</title>
</head>
<body>
 <div class="root">
  <div class="item">
   <b>UserGeneratedElementName1:</b> Whatever blah blah
   <b>UserGeneratedElementName2:</b> Whatever blah blah
  </div>
  <div class="item">
   <b>UserGeneratedElementName3:</b> Whatever blah blah
  </div>
  ...
  ...
  Other transformed items...
 </div>
</body>
</html>

I have tried to get a grasp of the XSLT syntax, but all the guides were either too vague to help me with this or too deep. Also XSLT syntax seems quite confusing.
Thanks in advance.

  • 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-22T20:38:35+00:00Added an answer on May 22, 2026 at 8:38 pm

    Take a look at this question here

    Is there an XSLT name-of element?

    You can use

    <xsl:value-of select ="name(.)"/>
    

    or

    <xsl:value-of select ="local-name()"/>
    

    to get the name of a node, depending on if you want to include the full prefixed name, or just the local portion.

    You should be able to piece those together with xsl:for-each blocks to iterate through the first 3 levels of items and generate the HTML you’re looking for.

    Something like this would work for a fixed number of levels.

        <xsl:for-each select="*">
            <html>
                <head>
                    <title><xsl:value-of select="local-name()" /></title>
                </head>
                <body>
                    <div class="root">
                        <xsl:for-each select="*">
                            <div>
                                <xsl:attribute name="class">
                                    <xsl:value-of select="local-name()" />
                                </xsl:attribute>
                                <xsl:for-each select="*">
                                    <b><xsl:value-of select="local-name()" />:</b> <xsl:value-of select="." />
                                </xsl:for-each>
                            </div>
                        </xsl:for-each>
                    </div>
                </body>
            </html>
        </xsl:for-each>
    

    A more generic approach would look something more like:

    <?xml version="1.0"?> 
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        version="1.0">
    
    <xsl:output method="html" indent="yes" version="4.0"/>
    <xsl:template match="/">
        <xsl:for-each select="*">
            <html>
                <head>
                    <title><xsl:value-of select="local-name()" /></title>
                </head>
                <body>
                    <div class="root">
                            <xsl:call-template name="recurseElement">
                                <xsl:with-param name="element" select="." />
                            </xsl:call-template>
                    </div>
                </body>
            </html>
        </xsl:for-each>
    </xsl:template>
    <xsl:template name="recurseElement">
        <xsl:param name="element" />
        <xsl:for-each select="$element/*">
            <xsl:choose>
                    <xsl:when test="count(child::*)>0">
                        <div>
                            <xsl:attribute name="class">
                                <xsl:value-of select="local-name()" />
                            </xsl:attribute>
                            <xsl:call-template name="recurseElement">
                                <xsl:with-param name="element" select="." />
                            </xsl:call-template>
                        </div>
                    </xsl:when>
                    <xsl:otherwise>
                        <b><xsl:value-of select="local-name()" />:</b> <xsl:value-of select="." />
                    </xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML document something like ::: <?xml version=1.0 encoding=utf-8?> <?mso-application progid=Excel.Sheet?> <Workbook
I have generated this WSDL file... <?xml version=1.0 encoding=UTF-8 standalone=yes?> <!-- Generated by JAX-WS
I have an XML document generated from an external application, but that application does
I have an XML document looking similar to this: <items> <item cat=1 owner=14>bla</item> <item
I have generated a set of classes using xsd.exe and created an XML document
I have an XML document generated by a 3rd party using BizTalk, and I
I have a C# application that generates an html document from transforming an xml
I have an XML document that I generate from an Entity Framework object. The
I have an XML document with un-namespaced elements, and I want to use XSLT
I have an XML document: var xml:XML = new XML(<rootNode> <head> <meta name=template content=Default

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.