Subject: [xsl] Converting XML to CSV - how to eliminate output whitespace and blank lines? From: "ohaya ohaya@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 6 Nov 2023 02:13:22 -0000 |
Hi, I am trying to use XSLT to convert an XML file to a CSV, where the CSV has the node names+node values. Thus far I have this XSLT (note: I can only use XSLT 1.0 because I am going be using xsltproc): <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- <xsl:output method="html" /> --> <xsl:output method="text" encoding="UTF-8" disable-output-escaping="YES"/> <xsl:template match="*[not(*)]"> <xsl:value-of select="local-name()"/> <xsl:text>,</xsl:text> <xsl:value-of select="."/> </xsl:template> </xsl:stylesheet> Here's an example XML file: <record> <rule> <customer>1234</customer> <schemaName>schema_name</schemaName> <schemaVersion>1.0</schemaVersion> </rule> <identifier> <PN_ID>1111111111</PN_ID> </identifier> <adrRecord> <PN_ID>1111111</PN_ID> <personnel> <ADM_ORG_CD>urn:NORM:DEPT</ADM_ORG_CD> </personnel> <enterpriseUser> <entUserRoles>a:b:c</entUserRoles> </enterpriseUser> </adrRecord> </record> and here's the output when I run the XSLT using xsltproc: =========================================== customer,1234 schemaName,schema_name schemaVersion,1.0 PN_ID,1111111111 PN_ID,1111111 ADM_ORG_CD,urn:NORM:DEPT entUserRoles,a:b:c ============================================= Notice the whitespace in front of each line and also the blank lines between sub-nodes, e.g., so the output would be just: ============================================= customer,1234 schemaName,schema_name schemaVersion,1.0 PN_ID,1111111111 PN_ID,1111111 ADM_ORG_CD,urn:NORM:DEPT entUserRoles,a:b:c ============================================= Is it possible to remove/suppress both the whitespace and the blank lines using XSLT? I am currently having to pipe the output through a couple of SEDs, and I'd prefer not to have to do that. Thanks in advance!! Jim
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] XSL-List Guidelines, B Tommie Usdin btusd | Thread | Re: [xsl] Converting XML to CSV - h, Graydon graydon@xxxx |
Re: [xsl] problem with XPath count(, Bauman, Syd s.bauman | Date | Re: [xsl] Converting XML to CSV - h, Graydon graydon@xxxx |
Month |