私は、既存の xslt 文字列を変更する任務を負っています。私がする必要があるのは、行末のコンマを削除することです。コンマの原因がわかりました。問題は、コンマを削除するように変更すると、csv ファイルが、レコード、改行、レコードなどではなく、1 つの大きな実行文字列になることです。
xslt は次のとおりです。
public const string XSLT = @"
<xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform""
xmlns:msxsl=""urn:schemas-microsoft-com:xslt"" exclude-result-prefixes=""msxsl"">
<xsl:output method=""text"" encoding=""us-ascii"" />
<xsl:template match=""DataRow"">Incident No.,Incident Date,Location Code,Location,Date Reported,Days away from Work (H),Is the incident OSHA Reportable?,Total Days Away From Work,Name of injured employee,Employee Type,Reported By,Witness (Name and Phone #),This Incident is an,""Select """"Injury"""" or choose Illness Type: (M)"",Was employee taken to the hospital?,Was this a recurring incident?,Cause of Injury,Injury Type,Body Part Injured,Body Fluid Exposure?,Did Injury/Illness occur on AECI premises?
<xsl:apply-templates select=""Data""/>
</xsl:template>
<xsl:template match=""Data"">
<xsl:for-each select=""*"">
<xsl:if test=""position() != last()"">
<xsl:value-of disable-output-escaping=""yes"" select="".""/>
<xsl:value-of select=""','""/>
</xsl:if>
<xsl:if test=""position() = last()"">
<xsl:value-of disable-output-escaping=""yes"" select="".""/>
</xsl:if>
</xsl:for-each>, <-----THIS IS WHAT IS CAUSING THE COMMA AT THE END OF THE LINE
</xsl:template>
</xsl:stylesheet>";
カンマを削除する前の csv ファイルは次のようになります。名前を削除して* *に置き換えました
Incident No.,Incident Date,Location Code,Location,Date Reported,Days away from Work (H),Is the incident OSHA Reportable?,Total Days Away From Work,Name of injured employee,Employee Type,Reported By,Witness (Name and Phone #),This Incident is an,"Select ""Injury"" or choose Illness Type: (M)",Was employee taken to the hospital?,Was this a recurring incident?,Cause of Injury,Injury Type,Body Part Injured,Body Fluid Exposure?,Did Injury/Illness occur on AECI premises?
2858,7/24/2012,HQ,Accounting and Finance,,,No,,,,,,,Environmental,No,,,,,,No,
2852,7/23/2012,TH,TH - RESULTS/LAB,2012-07-23t00:07:00,0,No,,****, ****,Represented,****, ****,,(1) Information Only,Environmental,No,,... Acid Chemicals ,... No Physical Injury,... Facial Bones ,,Yes,
行末のコメントを削除したいだけです。この末尾のコンマを削除すると、次のようになります。
Incident No.,Incident Date,Location Code,Location,Date Reported,Days away from Work (H),Is the incident OSHA Reportable?,Total Days Away From Work,Name of injured employee,Employee Type,Reported By,Witness (Name and Phone #),This Incident is an,"Select ""Injury"" or choose Illness Type: (M)",Was employee taken to the hospital?,Was this a recurring incident?,Cause of Injury,Injury Type,Body Part Injured,Body Fluid Exposure?,Did Injury/Illness occur on AECI premises?
2858,7/24/2012,HQ,Accounting and Finance,,,No,,,,,,,Environmental,No,,,,,,No2852,7/23/2012,TH,TH - RESULTS/LAB,2012-07-23t00:07:00,0,No,,****, ****,Represented,****, ****,,(1) Information Only,Environmental,No,,... Acid Chemicals ,... No Physical Injury,... Facial Bones ,,Yes2849,7/21/2012,HQ,New Madrid,,,No,,,,,,,Environmental,No,,,,,,