Advertisement

11.29.2005 at 09:07AM PST, ID: 21646666
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

need an xsl that will remove empty tags and attributes from an xml.

Asked by cjferris in Extensible Markup Language (XML), Extensible HTML (XHTML)

Tags: , , , ,

Hello

I would like help in creating an xsl (and to flatten out the learning curve). I’m new to using xsl, but have good experience with dom trees and xml. Using xsl looks like it can do many things I have been coding manually.  What I need now is to take a xml doc and remove all attributes and empty tags. (I consider empty tags as tag without any data).  To help illustrate this, below is a sample of the input/source xml and the resulting xml.

xml source

<Sales_ticket>
    <Sales_ticket_header>
      <Sales_ticket_header_Transmit_version/>
      <Sales_ticket_header_Store_number/>
      <Sales_ticket_header_Register_ID/>
      <Sales_ticket_header_Transaction_date/>
      <Sales_ticket_header_Transaction_time/>
      <Sales_ticket_header_Polled_date ref="XDT50">11232005</Sales_ticket_header_Polled_date>
      <Sales_ticket_header_Ticket_number ref="X50TICK">36154</Sales_ticket_header_Ticket_number>
      <Sales_ticket_header_Receptionist_ID ref="X50RECP">00</Sales_ticket_header_Receptionist_ID>
      <Sales_ticket_header_Employee_ID ref="X50EMPN">05</Sales_ticket_header_Employee_ID>
      <Sales_ticket_header_Customer_type ref="X50CTYP">4</Sales_ticket_header_Customer_type>
      <Sales_ticket_header_price_group ref="X50PGRP">020</Sales_ticket_header_price_group>
      <Sales_ticket_header_POS_sales_tax ref="X50STAX">000000.00</Sales_ticket_header_POS_sales_tax>
    </Sales_ticket_header>  
    <Sales_ticket_detail>
      <Sales_ticket_detail_Ticket_number ref="X51TICK">36154</Sales_ticket_detail_Ticket_number>
      <Sales_ticket_detail_Employee_ID ref="X51EMPN">05</Sales_ticket_detail_Employee_ID>
      <Sales_ticket_detail_Detail_price_group ref="X51PGRP">020</Sales_ticket_detail_Detail_price_group>
      <Sales_ticket_detail_Retail_or_service_flag ref="X51TYPE">S</Sales_ticket_detail_Retail_or_service_flag>
      <Sales_ticket_detail_Retail_or_service_number ref="X51COD1">00865</Sales_ticket_detail_Retail_or_service_number>
      <Sales_ticket_detail_Subservice_number ref="X51COD2">000</Sales_ticket_detail_Subservice_number>
      <Sales_ticket_detail_List_price ref="X51LPRC">000012.50</Sales_ticket_detail_List_price>
      <Sales_ticket_detail_Quantity_sold ref="X51QTYS">01</Sales_ticket_detail_Quantity_sold>
      <Sales_ticket_detail_Item_taxed ref="NG51ITAX">N</Sales_ticket_detail_Item_taxed>
    </Sales_ticket_detail>
    <Payment_detail>
      <Payment_detail_Ticket_number ref="X54TICK">36154</Payment_detail_Ticket_number>
      <Payment_detail_Payment_type ref="X54TYPE">1</Payment_detail_Payment_type>
      <Payment_detail_Amount_tendered ref="X54AMNT">0000000000050.00</Payment_detail_Amount_tendered>
      <Payment_detail_Amount_negative ref="NG54NEGA">N</Payment_detail_Amount_negative>
      <Payment_detail_Gift_certificate_number_redeemed ref="X54GCRD">000000000</Payment_detail_Gift_certificate_number_redeemed>
      <Payment_detail_Change_record ref="NG54CHNG">N</Payment_detail_Change_record>
      <Payment_detail_Change_amount ref="NG54CAMT">0000000000000.00</Payment_detail_Change_amount>
      <Credit_card_detail>
           <Credit_card_detail_Ticket_number ref="NG55TICK"/>
           <Credit_card_detail_Charge_amount ref="NG55CHGA"/>
      </Credit_card_detail>
     </Payment_detail>
</Sales_ticket>

desired xml result

<Sales_ticket>
    <Sales_ticket_header>
      <Sales_ticket_header_Polled_date>11232005</Sales_ticket_header_Polled_date>
      <Sales_ticket_header_Ticket_number>36154</Sales_ticket_header_Ticket_number>
      <Sales_ticket_header_Employee_ID>05</Sales_ticket_header_Employee_ID>
      <Sales_ticket_header_Customer_type>4</Sales_ticket_header_Customer_type>
      <Sales_ticket_header_price_group>020</Sales_ticket_header_price_group>
      <Sales_ticket_header_POS_sales_tax>000000.00</Sales_ticket_header_POS_sales_tax>
    </Sales_ticket_header>  
    <Sales_ticket_detail>
      <Sales_ticket_detail_Ticket_number>36154</Sales_ticket_detail_Ticket_number>
      <Sales_ticket_detail_Employee_ID>05</Sales_ticket_detail_Employee_ID>
      <Sales_ticket_detail_Detail_price_group>020</Sales_ticket_detail_Detail_price_group>
      <Sales_ticket_detail_service_flag>S</Sales_ticket_detail_service_flag>
      <Sales_ticket_detail_service_number>00865</Sales_ticket_detail_service_number>
      <Sales_ticket_detail_Subservice_number>000</Sales_ticket_detail_Subservice_number>
      <Sales_ticket_detail_List_price>000012.50</Sales_ticket_detail_List_price>
      <Sales_ticket_detail_Quantity_sold>01</Sales_ticket_detail_Quantity_sold>
      <Sales_ticket_detail_Item_taxed>N</Sales_ticket_detail_Item_taxed>
    </Sales_ticket_detail>
    <Payment_detail>
      <Payment_detail_Ticket_number>36154</Payment_detail_Ticket_number>
      <Payment_detail_Payment_type>1</Payment_detail_Payment_type>
      <Payment_detail_Amount_tendered>000000050.00</Payment_detail_Amount_tendered>
      <Payment_detail_Amount_negative>N</Payment_detail_Amount_negative>
      <Payment_detail_Gift_certificate_number_redeemed>000</Payment_detail_Gift_certificate_number_redeemed>
      <Payment_detail_Change_record>N</Payment_detail_Change_record>
      <Payment_detail_Change_amount>00000000.00</Payment_detail_Change_amount>
     </Payment_detail>
</Sales_ticket>

Basically I’m trying to reduce the document size before sending it on its way.

Here is what I got so far, it seems to just remove the attributes, but not the empty tags. Not sure what tells it to remove the attributes either.  So 500 points for one that does both, with comments telling what part does what.  Thanks.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" omit-xml-declaration="no"/>
<xsl:template match="* | /">
    <xsl:copy>
        <xsl:apply-templates/>
    </xsl:copy>
</xsl:template>
</xsl:stylesheet>
Start Free Trial
 
Loading Advertisement...
 
[+][-]11.29.2005 at 09:33AM PST, ID: 15381780

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.29.2005 at 10:40AM PST, ID: 15382342

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.29.2005 at 11:06AM PST, ID: 15382533

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Extensible Markup Language (XML), Extensible HTML (XHTML)
Tags: empty, remove, xsl, xml, tags
Sign Up Now!
Solution Provided By: Gertone
Participating Experts: 2
Solution Grade: A
 
 
[+][-]11.29.2005 at 11:06AM PST, ID: 15382538

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.30.2005 at 08:00AM PST, ID: 15389120

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.30.2005 at 08:08AM PST, ID: 15389198

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.30.2005 at 09:02AM PST, ID: 15389708

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.30.2005 at 09:45AM PST, ID: 15390091

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.30.2005 at 10:34AM PST, ID: 15390447

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32