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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:30:08+00:00 2026-05-18T02:30:08+00:00

I have some XML that stores column information and row data from a table

  • 0

I have some XML that stores column information and row data from a table in the following form:

<?xml version="1.0" encoding="utf-8"?>
<table>
  <columns>
    <column id="1">
      <name>Date</name>
      <type>Date</type>
    </column>
    <column id="2">
      <name>Name</name>
      <type>String</type>
    </column>
  </columns>
  <rows>
    <row id="1">
      <columns>
        <column id="1">
          <name>Date</name>
          <value>1-Dec-2010</value>
          <localDate>1-Dec-2010 00:00:00 GMT</localDate>
        </column>
        <column id="2">
          <name>Name</name>
          <value>Jim</value>
        </column>
      </columns>
    </row>
    <row id="2">
      <columns>
        <column id="1">
          <name>Date</name>
          <value>2-Dec-2010</value>
          <localDate>2-Dec-2010 00:00:00 GMT</localDate>
        </column>
        <column id="2">
          <name>Name</name>
          <value>Jane</value>
        </column>
      </columns>
    </row>
  </rows>
</table>

NOTE: This is a cut down version of my xml. I have a lot more rows and store a lot more information on each column.

Is it possible to apply an XSL transform that will iterate through each row in the xml and output each column value. If the column is of type DateTime (as specified in the column information) I want to output the localDate text value otherwise I will just output the value text value.

I can do a little XSL but I am unsure as to how you would check the different part of the document which would essentially map from the tableModel/rows/row/columns/column to the tableModel/columns/column.

I am essentially outputting this as CSV. I have code in place to append the column information for each /tableModel/rows/row/columns/column xml but I think this is unnecessary and it makes the xml too large for Netbeans/Visual Studio to handle (around 7MB).

The output I am trying to get is:

Date,Name
1-Dec-2010 00:00:00 GMT,Jim
2-Dec-2010 00:00:00 GMT,Jane

Many thanks,

Andez

  • 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-18T02:30:09+00:00Added an answer on May 18, 2026 at 2:30 am

    Well the following produces the described output for your input sample

    <xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0">
    
      <xsl:param name="sep" select="','"/>
      <xsl:param name="lf" select="'&#10;'"/>
    
      <xsl:output method="text"/>
    
      <xsl:template match="/">
        <xsl:apply-templates select="table/columns/column/name"/>
        <xsl:value-of select="$lf"/>
        <xsl:apply-templates select="table/rows/row"/>
      </xsl:template>
    
      <xsl:template match="column/name">
        <xsl:value-of select="."/>
        <xsl:if test="position() != last()">
          <xsl:value-of select="$sep"/>
        </xsl:if>
      </xsl:template>
    
      <xsl:template match="rows/row">
        <xsl:apply-templates select="columns/column"/>
        <xsl:value-of select="$lf"/>
      </xsl:template>
    
      <xsl:template match="row/columns/column[not(localDate)]">
        <xsl:value-of select="value"/>
        <xsl:if test="position() != last()">
          <xsl:value-of select="$sep"/>
        </xsl:if>
      </xsl:template>
    
      <xsl:template match="row/columns/column[localDate]">
        <xsl:value-of select="localDate"/>
        <xsl:if test="position() != last()">
          <xsl:value-of select="$sep"/>
        </xsl:if>
      </xsl:template>
    
    </xsl:stylesheet>
    

    but it does not look at the corresponding column type, it simply outputs the localDate element if that is present. Does that suffice?
    Please also state whether you can use XSLT 2.0 (as implemented by AltovaXML Tools or Saxon 9), that makes such stuff easier.

    [edit] I wanted to use a key in match pattern and though that is not allowed in XSLT 1.0 but it seems it works so the following is a better implementation of your requirement:

    <xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0">
    
      <xsl:param name="sep" select="','"/>
      <xsl:param name="lf" select="'&#10;'"/>
    
      <xsl:key name="k1" match="table/columns/column" use="@id"/>
    
      <xsl:output method="text"/>
    
      <xsl:template match="/">
        <xsl:apply-templates select="table/columns/column/name"/>
        <xsl:value-of select="$lf"/>
        <xsl:apply-templates select="table/rows/row"/>
      </xsl:template>
    
      <xsl:template match="column/name">
        <xsl:value-of select="."/>
        <xsl:if test="position() != last()">
          <xsl:value-of select="$sep"/>
        </xsl:if>
      </xsl:template>
    
      <xsl:template match="rows/row">
        <xsl:apply-templates select="columns/column"/>
        <xsl:value-of select="$lf"/>
      </xsl:template>
    
      <xsl:template match="row/columns/column[not(key('k1', @id)/type = 'Date')]">
        <xsl:value-of select="value"/>
        <xsl:if test="position() != last()">
          <xsl:value-of select="$sep"/>
        </xsl:if>
      </xsl:template>
    
      <xsl:template match="row/columns/column[key('k1', @id)/type = 'Date']">
        <xsl:value-of select="localDate"/>
        <xsl:if test="position() != last()">
          <xsl:value-of select="$sep"/>
        </xsl:if>
      </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 some xml data stored in an XML Column in a table in
I have a file which is an XML representation of some data that is
I have an application that stores xml documents inside a column on SQL Server.
I have some XML data stored in a varchar(max) column on SQL Server 2005.
I have a XML file template like this that comes from some IC chips,
I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>
So I have some XML in the following format: <somenode> <html xmlns=http://www.w3.org/1999/xhtml> <head> <title/>
Some Background info: My web application stores some XML in a Text column of
I have a column in SQL Server 2005 that stores a simple chunk of
I have a script that appends some rows to a table. One of the

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.