0
我的任務是對現有的xslt字符串進行更改。我需要做的是在行尾刪除逗號。我發現是什麼導致了逗號,問題是,當我進行更改以刪除逗號時,csv文件變成一個大的運行字符串,而不是具有記錄,新行,記錄等。xslt:在行尾刪除逗號,但不是新行
這裏是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,,,,,,
VS 2010沒有像單引號。我用雙引號替換了它們,這讓它很開心。不幸的是它沒有改變任何東西。 – 2012-07-26 13:52:29
啊,是的,你的XSLT被存儲在VB中的一個變量中,當引號出現時會變得混亂。無論如何,我已經通過回答修改了另一個建議。 – 2012-07-26 13:56:31
成功!非常感謝您的幫助。它工作完美。我一定會將它添加到我不斷增長的「知識書中!:) – 2012-07-26 14:02:00