我目前正在使用 xslt 将我的 xml 转换为我可以使用的格式的 xml。我有一个新要求,即以 csv 格式的文件提供转换后的输出 xml。
这是 xslt 之前的 xml:
<?xml version='1.0' encoding='UTF-8'?>
<bb:Report_Data xmlns:bb="urn:com.playdate.report/Absence_Balances-Outbound">
<bb:Report_Entry>
<bb:projectedBalanceTotal.principalId>1040182074</bb:projectedBalanceTotal.principalId>
<bb:All_Eligible_Time_Off_Plans_for_Worker>
<bb:projectedBalanceTotal.planCodeId>Sick</bb:projectedBalanceTotal.planCodeId>
<bb:projectedBalanceTotal.leaveDescription>Sick</bb:projectedBalanceTotal.leaveDescription>
<bb:projected_balance_accrual_amount_for_the_pay_period>0</bb:projected_balance_accrual_amount_for_the_pay_period>
</bb:All_Eligible_Time_Off_Plans_for_Worker>
<bb:All_Eligible_Time_Off_Plans_for_Worker>
<bb:projectedBalanceTotal.planCodeId>Vacation</bb:projectedBalanceTotal.planCodeId>
<bb:projectedBalanceTotal.leaveDescription>Vacation</bb:projectedBalanceTotal.leaveDescription>
<bb:projected_balance_accrual_amount_for_the_pay_period>3.323077</bb:projected_balance_accrual_amount_for_the_pay_period>
</bb:All_Eligible_Time_Off_Plans_for_Worker>
<bb:All_Eligible_Time_Off_Plans_for_Worker>
<bb:projectedBalanceTotal.planCodeId>Winter Recess</bb:projectedBalanceTotal.planCodeId>
<bb:projectedBalanceTotal.leaveDescription>Winter Recess</bb:projectedBalanceTotal.leaveDescription>
<bb:projected_balance_accrual_amount_for_the_pay_period>0</bb:projected_balance_accrual_amount_for_the_pay_period>
</bb:All_Eligible_Time_Off_Plans_for_Worker>
<bb:projectedBalanceTotal.effectiveDate1>08122012</bb:projectedBalanceTotal.effectiveDate1>
<bb:projectedBalanceTotal.effectiveDate2>08262012</bb:projectedBalanceTotal.effectiveDate2>
<bb:projectedBalanceTotal.effectiveDate3>09092012</bb:projectedBalanceTotal.effectiveDate3>
<bb:projectedBalanceTotal.employeeId>0260971</bb:projectedBalanceTotal.employeeId>
</bb:Report_Entry>
</bb:Report_Data>
这是在 @Tim C 的帮助下使用的 XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:bb="urn:com.playdate.report/Absence_Balances-Outbound">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<bb:Report_Data>
<xsl:apply-templates select="bb:Report_Data/bb:Report_Entry"/>
</bb:Report_Data>
</xsl:template>
<xsl:template match="bb:Report_Entry">
<xsl:apply-templates select="*[starts-with(local-name(),'projectedBalanceTotal.effectiveDate')]"/>
</xsl:template>
<xsl:template match="*[starts-with(local-name(),'projectedBalanceTotal.effectiveDate')]">
<xsl:apply-templates select="../bb:All_Eligible_Time_Off_Plans_for_Worker">
<xsl:with-param name="date" select="."/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="bb:All_Eligible_Time_Off_Plans_for_Worker">
<xsl:param name="date"/>
<projectedBalanceTotal>
<xsl:copy-of select="../bb:projectedBalanceTotal.principalId"/>
<xsl:copy-of select="*"/>
<bb:projectedBalanceTotal.effectiveDate>
<xsl:value-of select="$date"/>
</bb:projectedBalanceTotal.effectiveDate>
<xsl:copy-of select="../bb:projectedBalanceTotal.employeeId"/>
</projectedBalanceTotal>
</xsl:template>
</xsl:stylesheet>
这是输出:
<?xml version="1.0"?>
<bb:Report_Data xmlns:bb="urn:com.playdate.report/Absence_Balances-Outbound">
<projectedBalanceTotal>
<bb:projectedBalanceTotal.principalId>1040182074</bb:projectedBalanceTotal.principalId>
<bb:projectedBalanceTotal.planCodeId>Sick</bb:projectedBalanceTotal.planCodeId>
<bb:projectedBalanceTotal.leaveDescription>Sick</bb:projectedBalanceTotal.leaveDescription>
<bb:projected_balance_accrual_amount_for_the_pay_period>0</bb:projected_balance_accrual_amount_for_the_pay_period>
<bb:projectedBalanceTotal.effectiveDate>08122012</bb:projectedBalanceTotal.effectiveDate>
<bb:projectedBalanceTotal.employeeId>0260971</bb:projectedBalanceTotal.employeeId>
</projectedBalanceTotal>
<projectedBalanceTotal>
<bb:projectedBalanceTotal.principalId>1040182074</bb:projectedBalanceTotal.principalId>
<bb:projectedBalanceTotal.planCodeId>Vacation</bb:projectedBalanceTotal.planCodeId>
<bb:projectedBalanceTotal.leaveDescription>Vacation</bb:projectedBalanceTotal.leaveDescription>
<bb:projected_balance_accrual_amount_for_the_pay_period>3.323077</bb:projected_balance_accrual_amount_for_the_pay_period>
<bb:projectedBalanceTotal.effectiveDate>08122012</bb:projectedBalanceTotal.effectiveDate>
<bb:projectedBalanceTotal.employeeId>0260971</bb:projectedBalanceTotal.employeeId>
</projectedBalanceTotal>
<projectedBalanceTotal>
<bb:projectedBalanceTotal.principalId>1040182074</bb:projectedBalanceTotal.principalId>
<bb:projectedBalanceTotal.planCodeId>Winter Recess</bb:projectedBalanceTotal.planCodeId>
<bb:projectedBalanceTotal.leaveDescription>Winter Recess</bb:projectedBalanceTotal.leaveDescription>
<bb:projected_balance_accrual_amount_for_the_pay_period>0</bb:projected_balance_accrual_amount_for_the_pay_period>
<bb:projectedBalanceTotal.effectiveDate>08122012</bb:projectedBalanceTotal.effectiveDate>
<bb:projectedBalanceTotal.employeeId>0260971</bb:projectedBalanceTotal.employeeId>
</projectedBalanceTotal>
<projectedBalanceTotal>
<bb:projectedBalanceTotal.principalId>1040182074</bb:projectedBalanceTotal.principalId>
<bb:projectedBalanceTotal.planCodeId>Sick</bb:projectedBalanceTotal.planCodeId>
<bb:projectedBalanceTotal.leaveDescription>Sick</bb:projectedBalanceTotal.leaveDescription>
<bb:projected_balance_accrual_amount_for_the_pay_period>0</bb:projected_balance_accrual_amount_for_the_pay_period>
<bb:projectedBalanceTotal.effectiveDate>08262012</bb:projectedBalanceTotal.effectiveDate>
<bb:projectedBalanceTotal.employeeId>0260971</bb:projectedBalanceTotal.employeeId>
</projectedBalanceTotal>
<projectedBalanceTotal>
<bb:projectedBalanceTotal.principalId>1040182074</bb:projectedBalanceTotal.principalId>
<bb:projectedBalanceTotal.planCodeId>Vacation</bb:projectedBalanceTotal.planCodeId>
<bb:projectedBalanceTotal.leaveDescription>Vacation</bb:projectedBalanceTotal.leaveDescription>
<bb:projected_balance_accrual_amount_for_the_pay_period>3.323077</bb:projected_balance_accrual_amount_for_the_pay_period>
<bb:projectedBalanceTotal.effectiveDate>08262012</bb:projectedBalanceTotal.effectiveDate>
<bb:projectedBalanceTotal.employeeId>0260971</bb:projectedBalanceTotal.employeeId>
</projectedBalanceTotal>
<projectedBalanceTotal>
<bb:projectedBalanceTotal.principalId>1040182074</bb:projectedBalanceTotal.principalId>
<bb:projectedBalanceTotal.planCodeId>Winter Recess</bb:projectedBalanceTotal.planCodeId>
<bb:projectedBalanceTotal.leaveDescription>Winter Recess</bb:projectedBalanceTotal.leaveDescription>
<bb:projected_balance_accrual_amount_for_the_pay_period>0</bb:projected_balance_accrual_amount_for_the_pay_period>
<bb:projectedBalanceTotal.effectiveDate>08262012</bb:projectedBalanceTotal.effectiveDate>
<bb:projectedBalanceTotal.employeeId>0260971</bb:projectedBalanceTotal.employeeId>
</projectedBalanceTotal>
<projectedBalanceTotal>
<bb:projectedBalanceTotal.principalId>1040182074</bb:projectedBalanceTotal.principalId>
<bb:projectedBalanceTotal.planCodeId>Sick</bb:projectedBalanceTotal.planCodeId>
<bb:projectedBalanceTotal.leaveDescription>Sick</bb:projectedBalanceTotal.leaveDescription>
<bb:projected_balance_accrual_amount_for_the_pay_period>0</bb:projected_balance_accrual_amount_for_the_pay_period>
<bb:projectedBalanceTotal.effectiveDate>09092012</bb:projectedBalanceTotal.effectiveDate>
<bb:projectedBalanceTotal.employeeId>0260971</bb:projectedBalanceTotal.employeeId>
</projectedBalanceTotal>
<projectedBalanceTotal>
<bb:projectedBalanceTotal.principalId>1040182074</bb:projectedBalanceTotal.principalId>
<bb:projectedBalanceTotal.planCodeId>Vacation</bb:projectedBalanceTotal.planCodeId>
<bb:projectedBalanceTotal.leaveDescription>Vacation</bb:projectedBalanceTotal.leaveDescription>
<bb:projected_balance_accrual_amount_for_the_pay_period>3.323077</bb:projected_balance_accrual_amount_for_the_pay_period>
<bb:projectedBalanceTotal.effectiveDate>09092012</bb:projectedBalanceTotal.effectiveDate>
<bb:projectedBalanceTotal.employeeId>0260971</bb:projectedBalanceTotal.employeeId>
</projectedBalanceTotal>
<projectedBalanceTotal>
<bb:projectedBalanceTotal.principalId>1040182074</bb:projectedBalanceTotal.principalId>
<bb:projectedBalanceTotal.planCodeId>Winter Recess</bb:projectedBalanceTotal.planCodeId>
<bb:projectedBalanceTotal.leaveDescription>Winter Recess</bb:projectedBalanceTotal.leaveDescription>
<bb:projected_balance_accrual_amount_for_the_pay_period>0</bb:projected_balance_accrual_amount_for_the_pay_period>
<bb:projectedBalanceTotal.effectiveDate>09092012</bb:projectedBalanceTotal.effectiveDate>
<bb:projectedBalanceTotal.employeeId>0260971</bb:projectedBalanceTotal.employeeId>
</projectedBalanceTotal>
</bb:Report_Data>
我有一个紧急要求,需要 csv 格式的每条记录,例如:
projectedBalanceTotal.principalId, projectedBalanceTotal.planCodeId, projectedBalanceTotal.leaveDescription, projected_balance_accrual_amount_for_the_pay_period, projectedBalanceTotal.effectiveDate, projectedBalanceTotal.employeeId
1040182074, Sick, Sick, 0, 08122012, 0260971
1040182074, Vacation, Vacation, 3.323077, 0260971
1040182074, Winter Recess, Winter Recess, 0, 0260971
等等等等
我可以在这个模板上堆叠另一个模板来完成这个吗?