-2

I am attempting to learn some XLST for extracting data from EDi 837/835 files. The below will place the fields specified from Loop 2100 in to a cvs format, but not the fields from Loop 2110. The stylesheet below it will return the fields from Loop 2110 but not 2100. How could I combine the loops to return the fields from both 2100 and 2110 in 1 stylesheet? I have tried several options and have been unsuccessful returning all fields in a csv format. Any ideas? Any help is greatly appreciated. The 835 Test file id is at the bottom.

<?xml version="1.0" encoding="utf-8"?>
<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" indent="yes"/>

<xsl:template match="Interchange">
<xsl:apply-templates select="FunctionGroup/Transaction/Loop[@LoopId='2000']/Loop 
  [@LoopId='2100']"/>
 </xsl:template>


 <xsl:template match="Loop[@LoopId='2100'] "> 
<xsl:variable name="trans" select="../../."/>
<xsl:variable name="payer" select="../../Loop[@LoopId='1000A']"/>
<xsl:variable name="payee" select="../../Loop[@LoopId='1000B']"/>
<xsl:variable name="payment" select="."/>
 <xsl:variable name="cas" select="../../Loop[@LoopId='2110']"/>
 <xsl:variable name="caxx" select="."/>

<xsl:value-of select="$trans/BPR/BPR16"/>
<xsl:value-of select="','"/>
<xsl:value-of select="$caxx/N1/N102"/>
<xsl:value-of select="','"/>
<xsl:value-of select="$payee/N1/N102"/>
<xsl:value-of select="','"/>
<xsl:value-of select="$payee/N1/N104"/>
<xsl:value-of select="','"/>
<xsl:value-of select="$payment/CLP/CLP01"/>
<xsl:value-of select="','"/>
<xsl:value-of select="$payment/CLP/CLP02"/>
<xsl:value-of select="','"/>
<xsl:value-of select="$payment/CLP/CLP03"/>
<xsl:value-of select="','"/>
<xsl:value-of select="$payment/NM1[NM101='QC']/NM103"/>
<xsl:value-of select="','"/>
<xsl:value-of select="$payment/NM1[NM101='QC']/NM104"/>
<xsl:value-of select="','"/>





 <xsl:value-of select="$cas/DTM[DTM01='472']/DTM02"/>
<xsl:value-of select="','"/>
 <xsl:value-of select="$payment/CAS[CAS01='CO']/CAS01"/>
 <xsl:value-of select="','"/>
  <xsl:value-of select="$payment/CAS[CAS01='CO']/CAS02"/>
 <xsl:value-of select="','"/>
      <xsl:value-of select="$payment/CAS[CAS01='CR']/CAS01"/>
 <xsl:value-of select="','"/>
 <xsl:value-of select="$payment/CAS[CAS01='CR']/CAS02"/>
 <xsl:value-of select="','"/>
      <xsl:value-of select="$payment/CAS[CAS01='OA']/CAS01"/>
 <xsl:value-of select="','"/>
 <xsl:value-of select="$payment/CAS[CAS01='OA']/CAS02"/>
 <xsl:value-of select="','"/>
         <xsl:value-of select="$payment/CAS[CAS01='PI']/CAS01"/>
 <xsl:value-of select="','"/>
  <xsl:value-of select="$payment/CAS[CAS01='PI']/CAS02"/>
 <xsl:value-of select="','"/>
<xsl:value-of select="$payment/CAS[CAS01='PR']/CAS01"/>
 <xsl:value-of select="','"/>
 <xsl:value-of select="$payment/CAS[CAS01='PR']/CAS02"/>
 <xsl:value-of select="','"/>
         <xsl:value-of select="$payment/REF[REF01='6R']/REF02"/>
 <xsl:value-of select="','"/>


    <xsl:value-of select="$cas/CAS[CAS01='PR']/CAS02"/>
 <xsl:value-of select="','"/>
 <xsl:text>&#x0A;</xsl:text>  
  </xsl:template>
 </xsl:stylesheet>

------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<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" indent="yes"/>

<xsl:template match="Interchange">
<xsl:apply-templates select="FunctionGroup/Transaction/Loop[@LoopId='2000']/Loop  
  [@LoopId='2100']/Loop[@LoopId='2110']"/>
 </xsl:template>


<xsl:template match="Loop[@LoopId='2110'] "> 
<xsl:variable name="trans" select="../../."/>
<xsl:variable name="payer" select="../../Loop[@LoopId='1000A']"/>
<xsl:variable name="payee" select="../../Loop[@LoopId='1000B']"/>
<xsl:variable name="payment" select="."/>
 <xsl:variable name="cas" select="../../Loop[@LoopId='2110']"/>
 <xsl:variable name="caxx" select="."/>

<xsl:value-of select="$trans/BPR/BPR16"/>
<xsl:value-of select="','"/>
<xsl:value-of select="$caxx/N1/N102"/>
<xsl:value-of select="','"/>
<xsl:value-of select="$payee/N1/N102"/>
<xsl:value-of select="','"/>
<xsl:value-of select="$payee/N1/N104"/>
<xsl:value-of select="','"/>
<xsl:value-of select="$payment/CLP/CLP01"/>
<xsl:value-of select="','"/>
<xsl:value-of select="$payment/CLP/CLP02"/>
<xsl:value-of select="','"/>
<xsl:value-of select="$payment/CLP/CLP03"/>
<xsl:value-of select="','"/>
<xsl:value-of select="$payment/NM1[NM101='QC']/NM103"/>
<xsl:value-of select="','"/>
<xsl:value-of select="$payment/NM1[NM101='QC']/NM104"/>
<xsl:value-of select="','"/>

 <xsl:value-of select="$cas/DTM[DTM01='472']/DTM02"/>
<xsl:value-of select="','"/>
 <xsl:value-of select="$payment/CAS[CAS01='CO']/CAS01"/>
 <xsl:value-of select="','"/>
  <xsl:value-of select="$payment/CAS[CAS01='CO']/CAS02"/>
 <xsl:value-of select="','"/>
      <xsl:value-of select="$payment/CAS[CAS01='CR']/CAS01"/>
 <xsl:value-of select="','"/>
 <xsl:value-of select="$payment/CAS[CAS01='CR']/CAS02"/>
 <xsl:value-of select="','"/>
      <xsl:value-of select="$payment/CAS[CAS01='OA']/CAS01"/>
 <xsl:value-of select="','"/>
 <xsl:value-of select="$payment/CAS[CAS01='OA']/CAS02"/>
 <xsl:value-of select="','"/>
         <xsl:value-of select="$payment/CAS[CAS01='PI']/CAS01"/>
 <xsl:value-of select="','"/>
  <xsl:value-of select="$payment/CAS[CAS01='PI']/CAS02"/>
 <xsl:value-of select="','"/>
<xsl:value-of select="$payment/CAS[CAS01='PR']/CAS01"/>
 <xsl:value-of select="','"/>
 <xsl:value-of select="$payment/CAS[CAS01='PR']/CAS02"/>
 <xsl:value-of select="','"/>
         <xsl:value-of select="$payment/REF[REF01='6R']/REF02"/>
 <xsl:value-of select=",'"/>


    <xsl:value-of select="$cas/CAS[CAS01='PR']/CAS02"/>
 <xsl:value-of select="','"/>
 <xsl:text>&#x0A;</xsl:text>
 </xsl:template>
 </xsl:stylesheet>

---------835 file

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 COUNTY ADAMH BD~
    N3*4817 STATE ROAD SUITE 203~
    N4*ASHTABULA*OH*44004~
  N1*PE*LAKE AREA RECOVERY CENTER *FI*346608640~
    N3*2801 C. COURT~
    N4*ASHTABULA*OH*44004~
    REF*PQ*1017~
  LX*1~
    CLP*444444*1*56.70*56.52*0*MC*0000000655555555*53~
      NM1*QC*1*FUDD*ELMER*S***MI*1333333~
      NM1*82*2*WECOVERWY SVCS*****FI*346608640~
      REF*F8*A76B04054~
      SVC*HC:H0005:HF:H9*56.70*56.52**6~
        DTM*472*20040205~
        CAS*CO*42*0.18*0~
        REF*6R*444444~
    CLP*999999*4*25.95*0*25.95*13*0000000555555555*11~
      NM1*QC*1*SAM*YOSEMITE*A***MI*3333333~
      NM1*82*2*ACME AGENCY*****FI*310626223~
      REF*F8*H57B10401~
      SVC*ZZ:M2200:HE*25.95*0**1~
        DTM*472*20021224~
        CAS*CR*18*25.95*0~
        CAS*CO*42*0*0~
        REF*6R*999999~
    CLP*888888*4*162.13*0*162.13*MC*0000000456789123*11~
      NM1*QC*1*SQUAREPANTS*BOB* ***MI*2222222~
      NM1*82*2*BIKINI AGENCY*****FI*310626223~
      REF*F8*H57B10401~
      SVC*ZZ:M151000:F0*162.13*0**1.9~
        DTM*472*20020920~
        CAS*CO*29*162.13*0*42*0*0~
        REF*6R*888888~
    CLP*111111*2*56.52*18.88*0*13*0000000644444444*53~
      NM1*QC*1*LEGHORN*FOGHORN*P***MI*7777777~
      NM1*82*2*CHICKENHAWK SVCS*****FI*346608640~
      REF*F8*A76B04054~
      SVC*HC:H0005:HF:H9*56.52*18.88**6~
        DTM*472*20031209~
        CAS*CO*42*0*0~
        CAS*OA*23*37.64*0~
        REF*6R*111111~
    CLP*121212*4*56.52*0*0*13*0000000646464640*53~
      NM1*QC*1*EXPLORER*DORA****MI*1717171~
      NM1*82*2*SWIPER AGENCY*****FI*346608640~
      REF*F8*A76B04054~
      SVC*HC:H0005:HF:H9*56.52*0**6~
        DTM*472*20031202~
        CAS*CO*42*0*0~
        CAS*OA*23*57.6*0*23*-1.08*0~
        REF*6R*121212~
    CLP*333333*1*74.61*59.69*14.92*13*0000000688888888*55~
      NM1*QC*1*BEAR*YOGI* ***MI*2222222~
      NM1*82*2*JELLYSTONE SVCS*****FI*346608640~
      REF*F8*A76B04054~
      SVC*ZZ:A0230:HF*74.61*59.69**1~
        DTM*472*20040203~
        CAS*PR*2*14.92*0~
        CAS*CO*42*0*0~
        REF*6R*333333~
    CLP*777777*25*136.9*0*0*13*0000000622222222*53~
      NM1*QC*1*BIRD*TWEETY*M***MI*4444444~
      NM1*82*2*GRANNY AGENCY*****FI*340716747~
      REF*F8*A76B03293~
      SVC*HC:H0015:HF:99:H9*136.9*0**1~
        DTM*472*20030911~
        CAS*PI*104*136.72*0~
        CAS*CO*42*0.18*0~
        REF*6R*777777~
    CLP*123456*22*-42.58*-42.58*0*13*0000000657575757*11~
      NM1*QC*1*SIMPSON*HOMER* ***MI*8787888~
      NM1*82*2*DOH GROUP*****FI*310626223~
      REF*F8*A57B04033~
      SVC*HC:H0036:GT:UK*-42.58*-42.58**-2~
        DTM*472*20040102~
        CAS*CR*141*0*0*42*0*0*22*0*0~
        CAS*OA*141*0*0~
        REF*6R*123456~
    CLP*090909*22*-86.76*-86.76*0*MC*0000000648484848*53~
      NM1*QC*1*DUCK*DAFFY*W***MI*1245849~
      NM1*82*2*ABTHSOLUTE HELP*****FI*346608640~
      REF*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~
        REF*6R*090909~
        AMT*AU*86.76~
        QTY*NE*53~
        LQ*HE*MA92~
  PLB*123456*19960930*CV:9876514*-1.27~
SE*97*07504123~
  GE*1*1~
IEA*1*004075123~
Tim C
  • 68,447
  • 14
  • 67
  • 90
tommyz
  • 13
  • 5
  • 1
    What does your XML input look like? Also, _"have been unsuccessful returning all fields in a csv format"_ is not sufficient information for anyone to help you. Please describe the issue in detail. – Jim Garrison Jun 23 '14 at 04:49
  • 1
    Something is missing from your description. The "835 file" that you show us is not XML - so it cannot be processed by XSLT, and you could not have obtained the result you claim. – michael.hor257k Jun 23 '14 at 05:28
  • The Edi format is fed to a parser, the output is controlled by the XLST. I don't have the actual XML available, but I can (somewhat)control the output by modifying the XSLT. I am a newbie and @Tim C was able to assist. – tommyz Jun 23 '14 at 18:53
  • You **can** see what the input XML looks like, by applying a stylesheet that contains nothing but the *identity transform template*. Then you'll know exactly what you're dealing with, instead of groping in the dark. – michael.hor257k Jun 24 '14 at 02:12

1 Answers1

0

Looking at your two stylesheets, the only differences is with the xsl:apply-templates

<xsl:apply-templates select="FunctionGroup/Transaction/Loop[@LoopId='2000']/Loop 
                             [@LoopId='2100']"/>

And the respective template match

<xsl:template match="Loop[@LoopId='2100'] ">

In both cases it is only the "2100" and "2110" that differ.

To allow the first XSLT to manage both "2100" and "2110" records, replace the existing single xsl:apply-templates with these:

<xsl:apply-templates select="FunctionGroup/Transaction/Loop[@LoopId='2000']/Loop[@LoopId='2100']"/>
<xsl:apply-templates select="FunctionGroup/Transaction/Loop[@LoopId='2000']/Loop[@LoopId='2110']"/>

Then, change the template match to this, to share the template

<xsl:template match="Loop[@LoopId='2100' or @LoopId='2110'] ">

Try this (abridged) XSLT, which combines your two XSLT stylesheets into one

<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" indent="yes"/>

<xsl:template match="Interchange">
    <xsl:apply-templates select="FunctionGroup/Transaction/Loop[@LoopId='2000']/Loop[@LoopId='2100']"/>
    <xsl:apply-templates select="FunctionGroup/Transaction/Loop[@LoopId='2000']/Loop[@LoopId='2110']"/>
</xsl:template>

<xsl:template match="Loop[@LoopId='2100' or @LoopId='2110'] "> 
    <xsl:variable name="trans" select="../../."/>
    <xsl:variable name="caxx" select="."/>
    <xsl:value-of select="$trans/BPR/BPR16"/>
    <xsl:value-of select="','"/>
    <xsl:value-of select="$caxx/N1/N102"/>
    <xsl:text>&#x0A;</xsl:text>  
</xsl:template>
</xsl:stylesheet>
Tim C
  • 68,447
  • 14
  • 67
  • 90
  • I have done as suggested, but changing the template match to only pulled the data from the 2100 Loop. If I do this I get all data from both Loops but only Loop 2110 is in the csv format? Example WECOVERWY SVCS FI 346608640 F8 A76B04054 ,,,,,,,,,20040205,,42,,,,,,,,,444444line,,, – tommyz Jun 23 '14 at 16:56
  • Is there a way to return all fields from both loops in csv format with out specifying the fields? Similar to a SQL Select * from table statement? – tommyz Jun 23 '14 at 17:10
  • I've made an edit to my answer to show a complete XSLT stylesheet to demonstrate. You can indeed make it more generic, but it's a bit hard to give a precise answer without seeing your input XML, or knowing what output you expect. (You would probably need to ask a whole new question for that anyway). – Tim C Jun 23 '14 at 17:16
  • Thank you @Tim C , I added and was able to get fields from both loops in csv format , but in different rows – tommyz Jun 23 '14 at 18:37