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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:36:06+00:00 2026-06-15T19:36:06+00:00

How do I transform a XML doc using XSTL when I don’t know the

  • 0

How do I transform a XML doc using XSTL when I don’t know the names of the nodes. So basically it should work universally, with any XML document.

Let’s say I got this XML document:

<?xml version="1.0"?>
<?xml-stylesheet href="transform.xsl" type="text/xsl" ?>
<!DOCTYPE cinema [
<!ELEMENT a (b*)>
<!ELEMENT b (c,d,e)>
<!ELEMENT c (#PCDATA)>
<!ELEMENT d (#PCDATA)>
<!ELEMENT e (#PCDATA)>
]>

<cinema>
<movie>
    <actor>Some actor</actor>
    <title>Some title</title>
    <year>Some year</year>
</movie>
</cinema>

How would I create an HTML table out of this? I know I can match the root element like this:

<xsl:template match="/">

Then I select all movies like this:

<xsl:for-each select="/*/*">

But how to I know get one row for each movie with three columns for actor, title & year? Especially since the XML file (movie) should be able to maybe only have 2 children or 5.

+++EDIT+++

If I do this:

<tr>
    <td><xsl:value-of select="."/></td>
</tr>

I get each movie’s details in one row. This is almost close to what I want to achieve. But how to I spread out the movie details over three columns in that row?

  • 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-15T19:36:08+00:00Added an answer on June 15, 2026 at 7:36 pm

    If you know you will always have three levels of elements (root, children and grandchildren) then something like this should do it:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:output method="html" />
    
      <xsl:template match="/">
        <html><body><xsl:apply-templates /></body></html>
      </xsl:template>
    
      <xsl:template match="/*">
        <table><xsl:apply-templates /></table>
      </xsl:template>
    
      <xsl:template match="/*/*">
        <tr><xsl:apply-templates /></tr>
      </xsl:template>
    
      <xsl:template match="/*/*/*">
        <td><xsl:apply-templates /></td>
      </xsl:template>
    </xsl:stylesheet>
    

    The / template matches the document node, /* matches first-level element children of the document node (i.e. the root element of the document), /*/* matches second-level children, etc.

    <xsl:apply-templates/> (with no select) will apply matching templates to all the child nodes of the current node, which includes child elements, text nodes, comments and processing instructions. As a result, you may need the root template to be

      <xsl:template match="/">
        <html><body><xsl:apply-templates select="*" /></body></html>
      </xsl:template>
    

    to select only child elements.

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

Sidebar

Related Questions

I'm using the javax.xml.transform.Transformer class to perform some XSLT translations, like so: TransformerFactory factory
I'm trying to transform one XML format to another using XSL. Try as I
I was using this extension method to transform very large xml files with an
I have written code in C# that should transform an XML with the help
I'm doing a xstl transformation with saxon from an XML document. The doc is
I am trying to transform XML basing on XSLT in Ruby/Nokogiri. doc = Nokogiri::XML(File.read('some_file.xml'))
I'm using iTextSharp library, specifically to view .xml documents and transform them into .pdf
I am using this method to transform an object to XML: protected XmlDocument SerializeAnObject(object
I am using MSXML 6.0 to perform a transform of my own XML into
I am using following code to remove some specific nodes from xml file..It show

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.