[Solved] How to parse complex and recurssive xml file having size 1GB and store it in csv using xslt


I couldn’t quite work out your logic but I think you may benefit from using a key here to look up the SecDef element using its MktSegGrp attribute value

<xsl:key name="MktSeg" match="SecDef" use="MktSegGrp/@MktSegID" />

So, for a given MktDef, you would get the SecDef elements for it like so

<xsl:variable name="secDef" select="key('MktSeg', @MktSegID)" />

Try this XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" >

  <xsl:output method="text"/>

  <xsl:key name="MktSeg" match="SecDef" use="MktSegGrp/@MktSegID" />

  <xsl:template match="https://stackoverflow.com/">
    <xsl:text>MktID,MktSegID,TxnTm,PriSetPx,QtSideInd,FastMktPctg,ImpldMktInd,MlegModel</xsl:text>
    <xsl:text>&#xA;</xsl:text>
    <xsl:for-each select="FIXML/Batch/MktDef">
      <xsl:variable name="secDef" select="key('MktSeg', @MktSegID)" />

      <xsl:for-each select="BaseTrdgRules">
        <xsl:variable name="header" select="concat(../@MktID,',', ../@MktSegID, ',', @QtSideInd, ',', @FastMktPctg)" />
        <xsl:choose>
          <xsl:when test="$secDef">
            <xsl:for-each select="$secDef">
              <xsl:variable name="baseTrg" select="MktSegGrp/SecTrdgRules/BaseTrdgRules" />
              <xsl:value-of select="concat($header, ',', @TxnTm, ',', @PriSetPx, ',', $baseTrg/@ImpldMktInd, ',', $baseTrg/@MlegModel, '&#xA;')"/>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="concat($header, ',,,,&#xA;')"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

3

solved How to parse complex and recurssive xml file having size 1GB and store it in csv using xslt