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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:05:28+00:00 2026-06-15T00:05:28+00:00

I have the following XML document: <?xml version=1.0 encoding=UTF-8 standalone=yes?> <Entity Type=defect> <Fields> <Field

  • 0

I have the following XML document:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Entity Type="defect">
  <Fields>
    <Field Name="user-28"/>
    <Field Name="user-29">
      <Value>1</Value>
    </Field>
    <Field Name="has-change">
      <Value></Value>
    </Field>
    ...

I am trying to convert this so that all Field elements become elements with the Name attribute converted to an element, and that it drops the Fields element. So far I have partial success using the following transformation:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0" encoding="UTF-8"
              indent="yes"/>
  <xsl:template match="//Entity">
    <xsl:copy>
      <xsl:apply-templates select="node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="Field">
    <xsl:element name="{@Name}">
      <xsl:value-of select="Value"/>
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

It results in the following, which is partly right, but it loses the Type attribute on the Entity element:

<?xml version="1.0" encoding="UTF-8"?>
<Entity>

    <user-28/>
    <user-29>1</user-29>
    <has-change/>

An additional complication is that I need this to work on the following document as well, which contains an Entities root node with multiple Entity nodes, without losing the root node:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Entities TotalResults="60">
  <Entity Type="defect">
    <Fields>
      <Field Name="id">
        <Value>1161</Value>
      </Field>
  • 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-15T00:05:34+00:00Added an answer on June 15, 2026 at 12:05 am

    <xsl:copy> only copies a node itself, none if its attributes or child nodes. Applied on attributes, it copies the complete attribute, i.e. name and value.

    When doing a transformation that preserves most of the document, it’s a good idea to use an identity transform template. What about this:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" version="1.0" encoding="UTF-8"
        indent="yes"/>
    
      <!-- Identity transform -->
      <xsl:template match="@*|node()">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
      </xsl:template>
    
      <!-- We don't want to copy <Fields>, just the contents -->
      <xsl:template match="Fields">
        <xsl:apply-templates/>
      </xsl:template>
    
      <xsl:template match="Field">
        <xsl:element name="{@Name}">
          <xsl:value-of select="Value"/>
        </xsl:element>
      </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 the following XML: <?xml version=1.0 encoding=UTF-8 standalone=yes?> <application xmlns=http://research.sun.com/wadl/2006/10> <doc xmlns:jersey=http://jersey.dev.java.net/ jersey:generatedBy=Jersey:
I have the following XML Document: <?xml version=\1.0\ encoding=\UTF-8\?> <atom:entry xmlns:atom=\http://www.w3.org/2005/Atom\ xmlns:apps=\http://schemas.google.com/apps/2006\ xmlns:gd=\http://schemas.google.com/g/2005\> <apps:property
I have the following string loaded to an XML document: <?xml version='1.0' encoding='utf-8'?> <soapenv:Envelope
I have the following xml document: <?xml version=1.0 encoding=UTF-8?> <root> <data> <child1>&#160;Well, some spaces
I have an loaded an XML document with the following structure: <?xml version=1.0 encoding=UTF-8
I have the following XML document <?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' xmlns:issues='http://schemas.google.com/projecthosting/issues/2009' gd:etag='W/DEAERH47eCl7ImA9WhZTFEQ.'><id>http://code.google.com/feeds/issues/p/chromium/issues/full/921</id><published>2008-09-03T22:51:22.000Z</published><updated>2011-03-19T01:05:05.000Z</updated><title>Incorrect rendering</title><content
I have the following XML document : <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE inventory SYSTEM books.dtd>
I have the following xml:- <?xml version=1.0 encoding=UTF-8?> <patent-assignment> <assignment-record> <correspondent> <name>NORTH AMERICA INTERNATIONAL
Consider we have the following xml document <?xml version=1.0 encoding=utf-8?> <Root> <Child /> </Root>
I have the following code. <?xml version=1.0 encoding=UTF-8 standalone=no?> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML

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.