使用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,'
')"/>
<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,'
')"/>
</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" />