【问题标题】:XSLT results on the same line?XSLT 结果在同一行?
【发布时间】:2014-08-12 19:14:55
【问题描述】:

我有这个示例卡通 EDI 文件 –

ISA*00* 00 *ZZ*ASHTB *ZZ*01017 *040315*1005*U*00401*004075123*0*P*:~ GS*HP*ASHTB*01017*20040315*1005*1*X*004010X091A1~ ST*835*07504123~ BPR*H*5.75*C*NON************20040315~ TRN*1*A04B001017.07504*1346000128~ DTM*405*20040308~ N1*PR*ASHTABULA 县 ADAMH BD~ N3*4817 国道套房 203~ N4*阿什塔布拉*OH*44004~ N1*PE*湖区恢复中心*FI*346608640~ N3*2801 C. COURT~ N4*阿什塔布拉*OH*44004~ 参考*PQ*1017~ LX*1~ 中电*444444*1*56.70*56.52*0*MC*0000000655555555*53~ NM1*QC*1*DUC4K*DAFFY*W***MI*1245849~ NM1*82*2*绝对帮助*****FI*346608640~ 编号*F8*A76B04054~ SVC*HC:H0004:HF:H9*-86.76*-86.76**-4~ DTM*150*20040210~ DTM*151*20040211~ CAS*CR*22*0*0*42*0*0~ CAS*OA*22*0*0~ 编号*6R*090909~ AMT*AU*86.76~ 数量*NE*53~ LQ*HE*MA92~ PLB*123456*19960930*CV:9876514*-1.27~ SE*27*07504123~ 通用电气*1*1~ 国际能源署*1*004075123~

在 EDI 记事本中呈现此 XML

  '<?xml version="1.0" encoding="iso-8859-1" ?><Batch>
<Interchange type="ISA" auth-qual="00" security-qual="00" sender-qual="ZZ" sender-id="ASHTB" receiver-qual="ZZ" receiver-id="01017" date="040315" time="1005" standard="U" version="00401" control="004075123" ack="0" test="P" ><FunctionalGroup type="GS" group="HP" sender="ASHTB" receiver="01017" date="20040315" time="1005" control="1" standard="X" version="004010X091A1" ><Document type="835" name="Health Care Claim Payment/Advice">
<RepeatingSegment type="ST">
<Segment type="ST" name="Transaction Set Header">
<Element type="143" name="Transaction Set Identifier Code" value="Health Care Claim Payment/Advice">835</Element>
<Element type="329" name="Transaction Set Control Number">07504123</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="BPR">
<Segment type="BPR" name="Beginning Segment for Payment Order/Remittance Advice">
<Element type="305" name="Transaction Handling Code" value="Notification Only">H</Element>
<Element type="782" name="Monetary Amount">5.75</Element>
<Element type="478" name="Credit/Debit Flag Code" value="Credit">C</Element>
<Element type="591" name="Payment Method Code" value="Non-Payment Data">NON</Element>
<Element type="373" name="Date">20040315</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="TRN">
<Segment type="TRN" name="Trace">
<Element type="481" name="Trace Type Code" value="Current Transaction Trace Numbers">1</Element>
<Element type="127" name="Reference Identification">A04B001017.07504</Element>
<Element type="509" name="Originating Company Identifier">1346000128</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="DTM">
<Segment type="DTM" name="Date/Time Reference">
<Element type="374" name="Date/Time Qualifier" value="Production">405</Element>
<Element type="373" name="Date">20040308</Element>
</Segment>
</RepeatingSegment>
<Loop type="N1">
<RepeatingSegment type="N1">
<Segment type="N1" name="Name">
<Element type="98" name="Entity Identifier Code" value="Payer">PR</Element>
<Element type="93" name="Name">ASHTABULA COUNTY ADAMH BD</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="N3">
<Segment type="N3" name="Address Information">
<Element type="166" name="Address Information">4817 STATE ROAD SUITE 203</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="N4">
<Segment type="N4" name="Geographic Location">
<Element type="19" name="City Name">ASHTABULA</Element>
<Element type="156" name="State or Province Code">OH</Element>
<Element type="116" name="Postal Code">44004</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="N1">
<Segment type="N1" name="Name">
<Element type="98" name="Entity Identifier Code" value="Payee">PE</Element>
<Element type="93" name="Name">LAKE AREA RECOVERY CENTER </Element>
<Element type="66" name="Identification Code Qualifier" value="Federal Taxpayer's Identification Number">FI</Element>
<Element type="67" name="Identification Code">346608640</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="N3">
<Segment type="N3" name="Address Information">
<Element type="166" name="Address Information">2801 C. COURT</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="N4">
<Segment type="N4" name="Geographic Location">
<Element type="19" name="City Name">ASHTABULA</Element>
<Element type="156" name="State or Province Code">OH</Element>
<Element type="116" name="Postal Code">44004</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="REF">
<Segment type="REF" name="Reference Identification">
<Element type="128" name="Reference Identification Qualifier" value="Payee Identification">PQ</Element>
<Element type="127" name="Reference Identification">1017</Element>
</Segment>
</RepeatingSegment>
</Loop>
<Loop type="LX">
<RepeatingSegment type="LX">
<Segment type="LX" name="Assigned Number">
<Element type="554" name="Assigned Number">1</Element>
</Segment>
</RepeatingSegment>
<Loop type="CLP">
<RepeatingSegment type="CLP">
<Segment type="CLP" name="Claim Level Data">
<Element type="1028" name="Claim Submitter's Identifier">444444</Element>
<Element type="1029" name="Claim Status Code" value="Processed as Primary">1</Element>
<Element type="782" name="Monetary Amount">56.70</Element>
<Element type="782" name="Monetary Amount">56.52</Element>
<Element type="782" name="Monetary Amount">0</Element>
<Element type="1032" name="Claim Filing Indicator Code" value="Medicaid">MC</Element>
<Element type="127" name="Reference Identification">0000000655555555</Element>
<Element type="1331" name="Facility Code Value">53</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="NM1">
<Segment type="NM1" name="Individual or Organizational Name">
<Element type="98" name="Entity Identifier Code" value="Patient">QC</Element>
<Element type="1065" name="Entity Type Qualifier" value="Person">1</Element>
<Element type="1035" name="Name Last or Organization Name">DUC4K</Element>
<Element type="1036" name="Name First">DAFFY</Element>
<Element type="1037" name="Name Middle">W</Element>
<Element type="66" name="Identification Code Qualifier" value="Member Identification Number">MI</Element>
<Element type="67" name="Identification Code">1245849</Element>
</Segment>
<Segment type="NM1" name="Individual or Organizational Name">
<Element type="98" name="Entity Identifier Code" value="Rendering Provider">82</Element>
<Element type="1065" name="Entity Type Qualifier" value="Non-Person Entity">2</Element>
<Element type="1035" name="Name Last or Organization Name">ABTHSOLUTE HELP</Element>
<Element type="66" name="Identification Code Qualifier" value="Federal Taxpayer's Identification Number">FI</Element>
<Element type="67" name="Identification Code">346608640</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="REF">
<Segment type="REF" name="Reference Identification">
<Element type="128" name="Reference Identification Qualifier" value="Original Reference Number">F8</Element>
<Element type="127" name="Reference Identification">A76B04054</Element>
</Segment>
</RepeatingSegment>
<Loop type="SVC">
<RepeatingSegment type="SVC">
<Segment type="SVC" name="Service Information">
<Element type="235" name="Product/Service ID Qualifier" value="Health Care Financing Administration Common Procedural Coding System (HCPCS) ">HC</Element>
<Element type="234" name="Product/Service ID">H0004</Element>
<Element type="1339" name="Procedure Modifier">HF</Element>
<Element type="1339" name="Procedure Modifier">H9</Element>
<Element type="782" name="Monetary Amount">-86.76</Element>
<Element type="782" name="Monetary Amount">-86.76</Element>
<Element type="380" name="Quantity">-4</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="DTM">
<Segment type="DTM" name="Date/Time Reference">
<Element type="374" name="Date/Time Qualifier" value="Service Period Start">150</Element>
<Element type="373" name="Date">20040210</Element>
</Segment>
<Segment type="DTM" name="Date/Time Reference">
<Element type="374" name="Date/Time Qualifier" value="Service Period End">151</Element>
<Element type="373" name="Date">20040211</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="CAS">
<Segment type="CAS" name="Claims Adjustment">
<Element type="1033" name="Claim Adjustment Group Code" value="Correction and Reversals">CR</Element>
<Element type="1034" name="Claim Adjustment Reason Code">22</Element>
<Element type="782" name="Monetary Amount">0</Element>
<Element type="380" name="Quantity">0</Element>
<Element type="1034" name="Claim Adjustment Reason Code">42</Element>
<Element type="782" name="Monetary Amount">0</Element>
<Element type="380" name="Quantity">0</Element>
</Segment>
<Segment type="CAS" name="Claims Adjustment">
<Element type="1033" name="Claim Adjustment Group Code" value="Other adjustments">OA</Element>
<Element type="1034" name="Claim Adjustment Reason Code">22</Element>
<Element type="782" name="Monetary Amount">0</Element>
<Element type="380" name="Quantity">0</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="REF">
<Segment type="REF" name="Reference Identification">
<Element type="128" name="Reference Identification Qualifier" value="Provider Control Number">6R</Element>
<Element type="127" name="Reference Identification">090909</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="AMT">
<Segment type="AMT" name="Monetary Amount">
<Element type="522" name="Amount Qualifier Code" value="Coverage Amount">AU</Element>
<Element type="782" name="Monetary Amount">86.76</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="QTY">
<Segment type="QTY" name="Quantity">
<Element type="673" name="Quantity Qualifier" value="Non-Covered - Estimated">NE</Element>
<Element type="380" name="Quantity">53</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="LQ">
<Segment type="LQ" name="Industry Code">
<Element type="1270" name="Code List Qualifier Code" value="Claim Payment Remark Codes">HE</Element>
<Element type="1271" name="Industry Code">MA92</Element>
</Segment>
</RepeatingSegment>
</Loop>
</Loop>
</Loop>
<RepeatingSegment type="PLB">
<Segment type="PLB" name="Provider Level Adjustment">
<Element type="127" name="Reference Identification">123456</Element>
<Element type="373" name="Date">19960930</Element>
<Element type="426" name="Adjustment Reason Code" value="Capital Passthru">CV</Element>
<Element type="127" name="Reference Identification">9876514</Element>
<Element type="782" name="Monetary Amount">-1.27</Element>
</Segment>
</RepeatingSegment>
<RepeatingSegment type="SE">
<Segment type="SE" name="Transaction Set Trailer">
<Element type="96" name="Number of Included Segments">27</Element>
<Element type="329" name="Transaction Set Control Number">07504123</Element>
</Segment>
</RepeatingSegment>
</Document>
</FunctionalGroup>
</Interchange>
</Batch>'

**当我应用此 XSLT 时**

<?xml version="1.0" encoding="utf-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="text" indent="no"/>
  <xsl:strip-space elements="*"/>
  <xsl:strip-space  elements="*"/>

  <xsl:template match="*|@*">
    <xsl:apply-templates/>
    <xsl:value-of select="','"/>
    <xsl:text>&#xa;</xsl:text>


    <xsl:value-of select="','"/>
  </xsl:template>
  <xsl:template match="text()">
    <xsl:value-of select="."/>
    <xsl:if test="../following-sibling::*/text()">
      <xsl:text>,</xsl:text>
    </xsl:if>
  </xsl:template>

</xsl:transform>

* 我得到这些结果*

00,,
,,
,00,,
,,
,ZZ,,
,ASHTB          ,,
,ZZ,,
,01017          ,,
,040315,,
,1005,,
,U,,
,00401,,
,004075123,,
,0,,
,P,
,,
,,
,,
,,
,HP,,
,ASHTB,,
,01017,,
,20040315,,
,1005,,
,1,,
,X,,
,004010X091A1,
,,
,835,,
,07504123,
,,
,H,,
,5.75,,
,C,,
,NON,,
,,
,,
,,
,,
,,
,,
,,
,,
,,
,,
,,
,20040315,
,,
,1,,
,A04B001017.07504,,
,1346000128,
,,
,405,,
,20040308,
,,
,PR,,
,ASHTABULA COUNTY ADAMH BD,
,,
,4817 STATE ROAD SUITE 203,
,,
,ASHTABULA,,
,OH,,
,44004,
,,
,,
,PE,,
,LAKE AREA RECOVERY CENTER ,,
,FI,,
,346608640,
,,
,2801 C. COURT,
,,
,ASHTABULA,,
,OH,,
,44004,
,,
,PQ,,
,1017,
,,
,,
,1,
,,
,444444,,
,1,,
,56.70,,
,56.52,,
,0,,
,MC,,
,0000000655555555,,
,53,
,,
,QC,,
,1,,
,DUC4K,,
,DAFFY,,
,W,,
,,
,,
,MI,,
,1245849,
,,
,82,,
,2,,
,ABTHSOLUTE HELP,,
,,
,,
,,
,,
,FI,,
,346608640,
,,
,F8,,
,A76B04054,
,,
,HC,,
,H0004,,
,HF,,
,H9,
,,
,-86.76,,
,-86.76,,
,,
,-4,
,,
,150,,
,20040210,
,,
,151,,
,20040211,
,,
,CR,,
,22,,
,0,,
,0,,
,42,,
,0,,
,0,
,,
,OA,,
,22,,
,0,,
,0,
,,
,6R,,
,090909,
,,
,AU,,
,86.76,
,,
,NE,,
,53,
,,
,HE,,
,MA92,
,,
,,
,,
,,
,123456,,
,19960930,,
,CV,,
,9876514,
,,
,-1.27,
,,
,27,,
,07504123,
,,
,,
,1,,
,1,
,,
,,
,1,,
,004075123,
,,
,,

,

哪些是我想要的结果 - 逗号替换段行终止符 ~。但是,我需要将所有这些结果放在同一行上,如果存在捆绑情况,则将这些结果放在新行上。我不知道如何实现?逗号创建的空字段是可以的,我可以稍后处理,我只需要将所有字段和 edi 段终止符 ~ 替换为逗号而不连接到其他字段。

我似乎缺少一些简单的东西,我是 XSLT 的新手吗,谢谢您的帮助。

【问题讨论】:

  • 请注意,您在 XSL 中有两个 strip-space 指令,这是不正确的,但不是问题的原因。下面的答案涵盖了这一点。

标签: xml xslt edi


【解决方案1】:

当你使用这个时:

  <xsl:template match="*|@*">
    <xsl:apply-templates/>
    <xsl:value-of select="','"/>
    <xsl:text>&#xa;</xsl:text>

您正在插入 每个元素后的(换行符)字符(您的模板适用于任何元素* 或任何属性@*)。取而代之的是,您应该在模板上仅使用 RepeatingSegment 元素,如下所示:

<xsl:template match="RepeatingSegment">
  <xsl:apply-templates/>
  <xsl:text>&#xa;</xsl:text>
</xsl:template>

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    这个:

    &lt;xsl:text&gt; &amp;#xa; &lt;/xsl:text&gt;

    是换行符。如果你删除它,它应该把它放在同一行。换行是导致换行的原因。

    【讨论】:

    • 这确实将所有内容放在了一行,但在我拥有的较大文件中,我需要在之后换行
    • 感谢@Andrew,这确实将所有内容放在了一行,但是在我拥有的较大文件中,我需要在每个 >QC - - QC1
    • 看IF测试。如果通过(元素 = QC),则使用换行代码。您是否研究过 EDI 翻译器?这东西让我头疼。 :)
    • @tommyz 你必须使用 XSLT 吗?如果是这样,为什么?当您可以使用 EDI 并使用拖放映射器将其直接写入数据库时​​,您似乎对数据的控制较少。很多人都有关于 SO 的 EDI 问题,它们非常相似:编写自己的解析器、没有 EDI 软件预算、紧迫的期限等。Altova 确实制作了一些不错的 XML 产品。你在考虑 MapForce 吗?
    • 我正在使用一个开源解析器,它使用 XSLT 来提取字段。使用 XSLT 执行 select * type 查询并将所有字段导出到 csv 文件似乎并不难。我想我只需要弄清楚如何在 >QCQC
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-08
    • 2020-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-12
    • 2021-01-30
    相关资源
    最近更新 更多