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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:51:32+00:00 2026-05-19T02:51:32+00:00

I have a scenario where I am exporting a .net dataset to an xml

  • 0

I have a scenario where I am exporting a .net dataset to an xml file, but I want to transform the stucture of the xml output to a more hierarchical structure. Below is the format of the dataset as exported by dataset.xmlwrite() method.

<NewDataSet>
    <Table>
        <id>100</id>
        <empname>Joe Smith</empname>
        <phone>111-111-1111</phone>
        <mobile>222-222-2222</mobile>

    </Table>
    <Table>
        <id>101</id>
        <empname>Ann Jensen</empname>
        <phone>111-111-0000</phone>
        <mobile>222-222-0000</mobile>
    </Table>
<NewDataSet>

I want to convert it to the below structure. I am a newbie at xsl transforms and I am not sure how keep the <Table> element from repeating for every record in the dataset.

<NewDataSet>
    <Table>
        <employee id="100">
            <empname>Joe Smith</empname>
            <phone>111-111-1111</phone>
            <mobile>222-222-2222</mobile>
        </employee>
        <employee id="101">
            <empname>Ann Jensen</empname>
            <phone>111-111-0000</phone>
            <mobile>222-222-0000</mobile>
        </employee>
    </Table>
<NewDataSet>

I tried using a combination of xsl:for-each and xsl:if statements to get what I wanted, but so far I have not been able to get it to work. Any assistance would be greatly appreciated.

  • 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-19T02:51:33+00:00Added an answer on May 19, 2026 at 2:51 am

    This transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="Table[1]">
      <Table>
       <xsl:apply-templates select="../Table/id"/>
      </Table>
     </xsl:template>
    
     <xsl:template match="Table[position()>1]"/>
    
     <xsl:template match="Table/id">
      <employee id="{.}">
       <xsl:apply-templates select=
          "following-sibling::node()"/>
      </employee>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document (corrected to be well-formed):

    <NewDataSet>
        <Table>
            <id>100</id>
            <empname>Joe Smith</empname>
            <phone>111-111-1111</phone>
            <mobile>222-222-2222</mobile>
        </Table>
        <Table>
            <id>101</id>
            <empname>Ann Jensen</empname>
            <phone>111-111-0000</phone>
            <mobile>222-222-0000</mobile>
        </Table>
    </NewDataSet>
    

    produces the wanted, correct result:

    <NewDataSet>
       <Table>
          <employee id="100">
             <empname>Joe Smith</empname>
             <phone>111-111-1111</phone>
             <mobile>222-222-2222</mobile>
          </employee>
          <employee id="101">
             <empname>Ann Jensen</empname>
             <phone>111-111-0000</phone>
             <mobile>222-222-0000</mobile>
          </employee>
       </Table>
    </NewDataSet>
    

    Explanation:

    1. The identity rule copies every node “as-is”.

    2. The first Table element is matched by an overriding template. This creates the only Table in the result and applies templates to the children of all Table elements.

    3. The id element is matched by an overriding template, that converts it to an employee element having an id attribute with the value of the id element. This also applies templates from inside the employee element to all other siblings of id and they are copied as-is by the identity template.

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

Sidebar

Related Questions

I have a scenario in which I'm serving a file from codebehind. which file,
We have a scenario where some .NET code is attempting to access the current
Coding in ASP.NET 4.0 / javascript/ jQuery/ WebServices The Scenario I have an analytics
Imagine a scenario you have a text file with say 10000 rows in it
I have scenario, I have two update panels on the page (both have update
I have scenario where I have to use the same XSD element for different
I have a path defined: when /the admin home\s?page/ /admin/ I have scenario that
I have a scenario that my load balancer translates port 80 from outside into
I have a scenario where customers are asking to develop a new project on
I have a scenario where I need to do the following in a transaction:

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.