。CSV文件中用于XML解析的XSL创建

问题描述 投票:0回答:1

使用XSL解析的.CSV文件中下面提到的XML文件的预期结果

样本XML文件

 <SCHOLARSHIP>
    <SCHOLARSHIP_DTL>
    <SCHOLARSHIP_NAME>Sports SCHOLARSHIP</SCHOLARSHIP_NAME>
    <ISSUE_DATE>21/12/2019</ISSUE_DATE>
    <AMOUNT>40000</AMOUNT>
    <STUDENTS>
    <STUDENT>
    <STUDENT_NAME>Alex</STUDENT_NAME>
    <SCHOOL_NAME>Monten</SCHOOL_NAME>
    </STUDENT>
    <STUDENT>
    <STUDENT_NAME>Lena</STUDENT_NAME>
    <SCHOOL_NAME>Convent</SCHOOL_NAME>
    </STUDENT>
    </STUDENTS>
    </SCHOLARSHIP_DTL>
 </SCHOLARSHIP>

使用上述示例数据通过Xsl解析的.csv中的预期输出

 SCHOLARSHIP_NAME,ISSUE_DATE,AMOUNT,STUDENT_NAME,SCHOOL_NAME
 Sports SCHOLARSHIP,21/12/2019,40000,Alex,Monten
 Sports SCHOLARSHIP,21/12/2019,40000,Lena,Convent

下面提到xsl并没有招到多个学生

    <xsl:template match="/">
     SCHOLARSHIP_NAME,ISSUE_DATE,AMOUNT,STUDENT_NAME,SCHOOL_NAME
    <xsl:for-each select="SCHOLARSHIP/SCHOLARSHIP_DTL"> 
    <xsl:value-of select="concat(SCHOLARSHIP_NAME,',',ISSUE_DATE,',',AMOUNT,',',STUDENTS/STUDENT/STUDENT_NAME,',',STUDENTS/STUDENT/SCHOOL_NAME,'&#xA;')"/>

xml csv xslt xml-parsing xslt-1.0
1个回答
0
投票
一种不处理带引号的字符串的幼稚方法将是以下XSLT-1.0样式表:

<xsl:template match="/"> SCHOLARSHIP_NAME,ISSUE_DATE,AMOUNT,STUDENT_NAME,SCHOOL_NAME <xsl:for-each select="SCHOLARSHIP/SCHOLARSHIP_DTL"> <xsl:for-each select="STUDENTS/STUDENT"> <xsl:value-of select="concat(../../SCHOLARSHIP_NAME,',',../../ISSUE_DATE,',',../../AMOUNT,',',STUDENT_NAME,',',SCHOOL_NAME,'&#xA;')"/> </xsl:for-each> </xsl:for-each> </xsl:template>

其输出是:

SCHOLARSHIP_NAME,ISSUE_DATE,AMOUNT,STUDENT_NAME,SCHOOL_NAME Sports SCHOLARSHIP,21/12/2019,40000,Alex,Monten Sports SCHOLARSHIP,21/12/2019,40000,Lena,Convent

首选的输出方法,指定为顶级元素(xsl:stylesheet的子元素),应为“文本”,如下所示:

<xsl:output method="text" />

© www.soinside.com 2019 - 2024. All rights reserved.