使用XSLD从XML转换为CSV

时间:2019-08-12 12:06:14

标签: xml xslt export-to-csv

我想知道您是否可以使用XSL导出到CSV到特定列。例如,在此示例中,某些员工缺少电子邮件,电话号码或部门。但是我希望结果是,如果缺少元素,则将其留空。

 <Employees>
   <Employee>
     <EmployeeID>1</EmployeeID>
     <EmpName>Homer Simpson</EmpName>
     <Department>IT1</Department>
     <PhNo>9111111111</PhNo>
     <Email>Homer.Simpson@gmail.com</Email>
     <Salary>99999</Salary>
   </Employee>
   <Employee>
     <EmployeeID>2</EmployeeID>
     <EmpName>John Smith</EmpName>
     <Department>IT2</Department>
     <PhNo>9222222222</PhNo>
     <Email>smith@gmail.com</Email>
     <Salary>99999</Salary>
   </Employee>
   <Employee>
     <EmployeeID>3</EmployeeID>
     <EmpName>Marge Simpson</EmpName>
     <Department>IT3</Department>
     <Salary>99999</Salary>
   </Employee>
   <Employee>
     <EmployeeID>4</EmployeeID>
     <EmpName>Bruce Wayne</EmpName>
     <Department>IT4</Department>
     <Email>batman@gmail.com</Email>
   </Employee>
 </Employees>


current xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:variable name="separator" select="'&#59;'" />
<xsl:variable name="newline" select="'&#10;'" />

<xsl:template match="/">

<xsl:for-each select="Employees/Employee">
                   
             <xsl:value-of select="EmployeeID" />
            <xsl:text>,</xsl:text>        
             <xsl:value-of select="EmpName"/>
            <xsl:text>,</xsl:text>  
             <xsl:value-of select="Department"/>  
             <xsl:text>,</xsl:text>   
             <xsl:value-of select="PhNo"/>
            <xsl:text>,</xsl:text>
             <xsl:value-of select="Email"/>
             <xsl:text>,</xsl:text>            
               <xsl:value-of select="Salary"/>

    

0 个答案:

没有答案