Sponsored Content
Full Discussion: XML to CSV specific
Top Forums Shell Programming and Scripting XML to CSV specific Post 302454482 by fpmurphy on Saturday 18th of September 2010 01:32:47 PM
Old 09-18-2010
The following XSLT stylesheet will transform your XML into CSV:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" encoding="iso-8859-1"/>

<xsl:strip-space elements="*" />

  <xsl:template match="*">
     <xsl:copy>
        <xsl:for-each select="@*">
           <xsl:if test="position() != last()"> "<xsl:value-of select="normalize-space(.)"/>",</xsl:if>
           <xsl:if test="position() = last()">"<xsl:value-of select="normalize-space(.)"/>"<xsl:text>
</xsl:text>
      </xsl:if>
        </xsl:for-each>
        <xsl:apply-templates />
     </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

Here is the output from the transformation
Code:
 "", "date", "", "1", "0", "ELEMITEM", "NO", "NOT A KEY", "19", "0", "BUSINESS_DATE", "NULL", "0", "0", "19", "0", "", "19", "0",""

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help to convert XML to CSV

Apologies if this has already been covered in this site somewhere, I did try looking but without any success. I am new to the whole XML thing, very late starter, and have a requirement to convert an XML fiule to a CSV fomat. I am crrently working on a Solaris OS. Does anyone have any suggestions,... (2 Replies)
Discussion started by: rossingi_33
2 Replies

2. Shell Programming and Scripting

CSV to XML

Iam pretty new to UNIX and would like to convert a CSV to an XML file using AWK scripts. Can anybody suggest a solution? My CSV file looks something like this : Serial No Growth% Annual % Commission % Unemployed % 1 35% 29% 59% 42% 2 61% ... (15 Replies)
Discussion started by: pjanakir
15 Replies

3. Shell Programming and Scripting

CSV processing to XML

Hi, i am really fresh with shell scripting and programming, i have an issue i am not able to solve to populate data on my server for Cisco IP phones. I have CSV file within the following format: ;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;... (9 Replies)
Discussion started by: angel2008
9 Replies

4. Shell Programming and Scripting

converting specific XML file to CSV

Hi, i would convert the following XML file : <?xml version="1.0" encoding="UTF-8" ?> <files xmlns="http://www.lotus.com/dxl/console"> <filedata notesversion="6" odsversion="43" logged="yes" backup="no" id="C12577E6:004B0DA3" iid="C12577E6:004B0DA8" link="1" dboptions="0,524288,0,0"> ... (24 Replies)
Discussion started by: Nicol
24 Replies

5. Shell Programming and Scripting

convert huge .xml file in .csv with specific column.

I have huge xml file in server and i want to convert it to .csv with specific column ... i have search in blog but i didn't get any usefully command. Thanks in advance (1 Reply)
Discussion started by: pareshkp
1 Replies

6. Shell Programming and Scripting

XML to CSV

I want to pharse below Xml Using Shell Scripting . Thanks in Advance <md> <neid> <neun>1523</neun> <nedn>XXX1212</nedn> <nesw>fffff12515</nesw> </neid> <mi> <mts>20141128001500</mts> <gp>550</gp> <mt>pmct1</mt> <mt>pmNo2</mt> <mt>pmNo3S</mt> <mv> <moid>Ma=1,Rn=1,Ul=311C</moid>... (6 Replies)
Discussion started by: pareshkp
6 Replies

7. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

8. UNIX and Linux Applications

Xml to csv

Hello, Does anyone know of a way to convert an .xml file (ONIX) to something more workable, like a .csv (or even .xls) file? Ideally something on the command line would be ideal, but not absolutely necessary. I would be dealing with .xml files of 125 MB+. I am using XQuartz in El Capitan. ... (17 Replies)
Discussion started by: palex
17 Replies

9. Shell Programming and Scripting

Moving XML tag/contents after specific XML tag within same file

Hi Forum. I have an XML file with the following requirement to move the <AdditionalAccountHolders> tag and its content right after the <accountHolderName> tag within the same file but I'm not sure how to accomplish this through a Unix script. Any feedback will be greatly appreciated. ... (19 Replies)
Discussion started by: pchang
19 Replies

10. UNIX for Beginners Questions & Answers

Xml to csv (again)

Hello, I have copied .xml code for a single item below. I am trying to extract three items (field indices*b244 (second occurrence), b203, and j151), so the desired output would be: 9780323013543 Manual of Natural Veterinary Medicine: Science and Tradition, 1e 68.95 A parallel solution,... (14 Replies)
Discussion started by: palex
14 Replies
TclXSLT(n)																TclXSLT(n)

__________________________________________________________________________________________________________________________________________________

NAME
::xslt::compile - SYNOPSIS
package require xslt xslt2.5 ::xslt ::xslt::compile doc ssheet method ? option value ... ? ? args ... ? ::xslt::extensionadd nsuri tcl-namespace _________________________________________________________________ DESCRIPTION
TclXSLT is a wrapper for the that allows an application to perform XSL transformations (XSLT). The package also provides a binding to the XSLT extension mechanism so that XSLT extension may be implemented using Tcl scripts. Transformation only works with documents created by TclDOM/libxml2. The TclXSLT package makes extensive use of Tcl objects. Compiled XSL stylesheets are stored as the internal representation of a Tcl object. Source and result documents are accessed via TclDOM's C interface as Tcl objects. This allows the application to cache parsed XML documents and compiled XSL stylesheets for better runtime performance. PACKAGES AND NAMESPACES
The TclXSLT package defines the package and also a Tcl namespace using that name. COMMANDS
::xslt::compile The ::xslt::compile command pre-compiles a stylesheet document. It returns a compiled stylesheet object and also defines a Tcl command to access the stylesheet. This Tcl command may be used to transform XML documents. NB. It is advisable to use the -baseuri option when parsing the source and stylesheet documents to allow external resources to be resolved. Stylesheet Command The stylesheet command created by ::xslt::compile command accesses a compiled stylesheet. Following is an example of how to use the stylesheet transform method. Command Methods The following command methods may be used: cget option Returns the value of an option. See below for the list of valid options. configure optionvalue Sets the value of an option. Available options are as follows: transform source ? name value? Performs an XSL transformation on the given source document. Stylesheet parameters may be specified as name-value pairs. The return result is the DOM token for the result document. Stylesheet Parameters Any number of name-value pairs may be specified as arguments to the stylesheet transform method. These are passed as values for parameters in the stylesheet. interprets the values as XPath expressions, where the context node is the root node for the source document. To pass a value as a string it must be XPath-quoted, for example set library "Gnome libxslt" $ssheet transform $source_doc library '$library' author "'Daniel Veillard'" node {/*/Element[3]} ::xslt::extension The ::xslt::extension command is used to manage extensions of the library. The add is used to register an extension. The remove is used to unregister an extension. See for more detail. EXTENSIONS
The TclXSLT package allows an application to bind Tcl scripts to the extension mechanism of . This means that Tcl scripts may provide the implementation of an XSLT extension element or function. The binding is achieved to associating a Tcl namespace with an XML namespace. Implementing An Extension The Tcl application uses the ::xslt::extension add command to register an extension. An XML Namespace for the extension is specified as an argument, along with a Tcl namespace that will provide implementations of extension elements and functions. For example, Everytime the ::xslt::transform command is executed, a newly-created XSLT engine is initialized. For each registered extension, every pro- cedure in the associated Tcl namespace is defined in the XSLT engine as either an extension element or an extension function. The proce- dure is defined as an extension function if it has a variable argument list, otherwise it is defined as an extension element. The proce- dure name is used as the local part of the extension name. For example, "myfunc" is defined as an extension function and "myelement" is defined as an extension element. Extension Functions The arguments to an extension function are converted to a string value and then passed as parameters to the Tcl procedure. The return result of the Tcl procedure becomes the return value of the extension function. The type of the result is preserved where possible, otherwise it is converted to a string value. Extension Elements Extension elements have not been implemented in TclXSLT v1.1. Using An Extension To invoke an extension in an XSL stylesheet, use the normal XSLT extension mechanism. The XML Namespace matches the extension to the reg- istered Tcl namespace (NB. the stylesheet author is free to choose any prefix for the extension namespace). For example, This stylesheet would result in the following Tcl script being evaluated: Tcl Built-In Commands Tcl TclXSLT(n)
All times are GMT -4. The time now is 02:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy