管道分隔的XML - 如何将数据复制/复制到不同的行

时间:2016-02-19 21:08:29

标签: xslt xslt-1.0 xslt-grouping

我是XSLT的新手,并尝试从XML转换为管道分隔格式。我遇到的问题是,在输出中,每个服务行都必须复制每个声明。

预期输出:

EP030315706890704|TESTSUBMITTER|FAMILY HEALTHCARE|1122334455|1|99214|179.00
EP030315706890704|TESTSUBMITTER|FAMILY HEALTHCARE|1122334455|2|2000F|0.00
EP030315706890705|TESTSUBMITTER2|FAMILY HEALTHCARE|1122334455|1|99214|179.00
EP030315706890705|TESTSUBMITTER2|FAMILY HEALTHCARE|1122334455|2|2000F|0.00

输入XML如下所示:

<payloadContainer>
   <afile>
      <clm>
         <hdr>
            <corn>EP030315706890704</corn>
            <idSend>112233445</idSend>
            <nmSend>TESTSUBMITTER</nmSend> 
         </hdr>
         <provBill>
            <name>
               <nmOrg>FAMILY HEALTHCARE</nmOrg>
            </name>
            <id T="XX" P="P">1122334455</id>
         </provBill>
         <serv S="1">
            <numLine>1</numLine>
            <prof>
               <px L="S">
                  <cdPx T="HC">99214</cdPx>
               </px>
               <amtChrg>179.00</amtChrg>
            </prof>


         </serv>
         <serv S="2">
            <numLine>2</numLine>
            <prof>
               <px L="S">
                  <cdPx T="HC">2000F</cdPx>
               </px>
               <amtChrg>0.00</amtChrg>
            </prof>
         </serv>
    </clm>
    <clm>
         <hdr>
            <corn>EP030315706890705</corn>
            <idSend>112233445</idSend>
            <nmSend>TESTSUBMITTER2</nmSend> 
         </hdr>
         <provBill>
            <name>
               <nmOrg>FAMILY HEALTHCARE</nmOrg>
            </name>
            <id T="XX" P="P">1122334455</id>
         </provBill>
         <serv S="1">
            <numLine>1</numLine>
            <prof>
               <px L="S">
                  <cdPx T="HC">99214</cdPx>
               </px>
               <amtChrg>179.00</amtChrg>
            </prof>
         </serv>
         <serv S="2">
            <numLine>2</numLine>
            <prof>
               <px L="S">
                  <cdPx T="HC">2000F</cdPx>
               </px>
               <amtChrg>0.00</amtChrg>
            </prof>
         </serv>
    </clm>
  </afile>
</payloadContainer>

所需的输出XML:

<Table>
<row>
.... All the fields represented here. 
</row>
</Table>

可能的解决方案:https://www.dropbox.com/s/wzvtzw7ihtgxx9o/claimtoRedshift.xsl

此方案动态创建两行。但是,我仍然坚持如何复制每个服务项目。

1 个答案:

答案 0 :(得分:0)

我没有看到链接的XSLT与此处提出的问题的关联。 AFAICT,以下样式表将返回预期的管道分隔输出:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>

<xsl:template match="/payloadContainer">
    <xsl:for-each select="afile/clm">
        <xsl:variable name="common">
            <xsl:value-of select="hdr/corn"/>
            <xsl:text>|</xsl:text>
            <xsl:value-of select="hdr/nmSend"/>
            <xsl:text>|</xsl:text>
            <xsl:value-of select="provBill/name/nmOrg"/>
            <xsl:text>|</xsl:text>
            <xsl:value-of select="provBill/id"/>
            <xsl:text>|</xsl:text>
        </xsl:variable>
        <xsl:for-each select="serv">
            <xsl:value-of select="$common"/>
            <xsl:value-of select="numLine"/>
            <xsl:text>|</xsl:text>
            <xsl:value-of select="prof/px/cdPx"/>
            <xsl:text>|</xsl:text>
            <xsl:value-of select="prof/amtChrg"/>
            <xsl:text>&#10;</xsl:text>
        </xsl:for-each>
    </xsl:for-each>
</xsl:template>

</xsl:stylesheet>