XML to CSV using XSLT help -


I want to convert XML to CSV using XSLT, but when against my input XSL is applied against SO SO Do:

 & lt; Viccord & gt; & Lt of DOMAINNAME & gt; 127.0.0.1 & lt; / DomainName & gt; & Lt; RegistryData & gt; & Lt; AbuseContact & gt; & Lt; Email & gt; Abuse@iana.org< / Email & gt; & Lt; Name & gt; Internet Corporation for Assigned Names and Numbers & lt; / Name & gt; & Lt; Phone & gt; + 1-310-301-5820 & lt; / Phone & gt; & Lt; / AbuseContact & gt; & Lt; AdministrativeContact i: nil = "true" /> & Lt; Billing contact: nil = "true" /> & Lt; CreatedDate / & gt; & Lt; RawText> ... & lt; / RawText> & Lt; Registrar & gt; & Lt; Address & gt; 4676 Admiralty Way, Suite 330 & lt; / Address & gt; & Lt; City & gt; Marina del Rey & lt; / City & gt; & Lt; Country & gt; America & lt; / Country & gt; & Lt; Name & gt; Internet Assigned Numbers Authority & lt; / Name & gt; & Lt; PostalCode & gt; 90292-6695 & lt; / PostalCode & gt; & Lt; StateProv & gt; CA & lt; / StateProv & gt; & Lt; / Registrar & gt; & Lt; TechnicalContact & gt; & Lt; Email & gt; Abuse@iana.org< / Email & gt; & Lt; Name & gt; Internet Corporation for Assigned Names and Numbers & lt; / Name & gt; & Lt; Phone & gt; + 1-310-301-5820 & lt; / Phone & gt; & Lt; / TechnicalContact & gt; & Lt; UpdatedDate & gt; 2010-04-14 & lt; / UpdatedDate & gt; & Lt; ZoneContact i: blue = "true" /> & Lt; / RegistryData & gt; & Lt; / WhoisRecord & gt; 

I end up with:

  abuse@iana.org assigned name and number + 1-310-301-5820 ,,, ... , 4676 for Internet Corporation Admiralty Way, Suite 330 Marina del Reuuse Intertext Assigned Number Authority 90292-6695 CA, abuse@iana.org International Corporation for Designated Name and Number + 1-310-301-5820, 2010-04- 14,  

My problem is that, resulting nodes (such as domain name element with IP address) and some children without nodes Received include (such as Children's Abus Kantaktkt).

I want to see all XML outputs in CSV form, and strings like: "abuse@iana.orgInternet Corporation + 1-310-301-5820 for the assigned name and number," Comma delimited .

My XSL is very dirty. Your help is appreciated :)

Here I am using XSL:

 & lt; Xsl: stylesheet version = "1.0" xmlns: xsl = "http://www.w3.org/1999/XSL/conversion" & gt; & Lt; Xsl: output method = "text" encoding = "ISO-885 9-1" /> & Lt; Xsl: strip-space element = "*" /> & Lt; Xsl: template match = "/ * / child :: *" & gt; & Lt; Xsl: each-select = "child :: *" & gt; & Lt; Xsl: if test = "status ()! = Last ()" & gt; & Lt; Xsl: Select the value = "normal-location (.)" / & Gt ;, & lt; / Xsl: if & gt; & Lt; Xsl: if test = "position () = last ()" & gt; & Lt; Xsl: Select the value = "normal-location (.)" / & Gt; & Lt; Xsl: text & gt; & # XD; & Lt; / XSL: text & gt; & Lt; / XSL: If & gt; & Lt; / XSL: for-each & gt; & Lt; / XSL: Templates & gt; & Lt; / XSL: stylesheet & gt; 

This simple change generates the desired result :

Pre> & lt; Xsl: stylesheet version = "1.0" xmlns: xsl = "http://www.w3.org/1999/XSL/Transform" & gt; & Lt; Xsl: output method = "text" /> & Lt; Xsl: strip-space element = "*" /> & Lt; Xsl: template match = "/" & gt; & Lt; Xsl: Apply-Select Template = "// Text ()" /> & Lt; / XSL: Templates & gt; & Lt; Xsl: template match = "text ()" & gt; & Lt; Xsl: copy-of select = "." / & Gt; & Lt; Xsl: if test = "no (condition () = last ())" & gt;, & lt; / Xsl: if & gt; & Lt; / XSL: Templates & gt; & Lt; / XSL: stylesheet & gt;

Note Usage:

  & lt; Xsl: strip-space element = "*" /> 

Update : AJ has raised this problem that the results can be grouped in a tricolor / Tups per line; it is not defined in this question How should the record / Tupal be really. Therefore, the current solution resolves two problems of white-space-only text nodes and missing commas, but do not grasp the output in records / tuples.


Comments