我的任务是对现有的 xslt 字符串进行更改。我需要做的是删除一行末尾的逗号。我找到了导致逗号的原因,问题是,当我进行更改以删除逗号时,csv 文件变成一个大的连续字符串,而不是有记录、新行、记录等。
这是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,,,,,,