Forum Stats

  • 3,874,118 Users
  • 2,266,686 Discussions
  • 7,911,730 Comments

Discussions

how to write xslt?

913349
913349 Member Posts: 255

hi all,

i have xslt below,

but it is not showing all records

it is overiding and it is showing last record .please help me.

  lxsl := '<?xml version="1.0" encoding="ISO-8859-1"?>

     <xsl:stylesheet version="1.0"

                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

                xmlns:exsl="http://exslt.org/functions"

                xmlns:set="http://exslt.org/sets"

                extension-element-prefixes="exsl"

                exclude-result-prefixes="set">

    <xsl:output method="html"/>

   

  <xsl:key name="rpt" match="*" use="REPORT_TYPE"/>

  <xsl:key name="vst" match="*" use="concat(REPORT_TYPE, &apos;-&apos;, VISIT_ID)"/>

  <xsl:key name="cmp" match="*" use="concat(concat(REPORT_TYPE, &apos;-&apos;, VISIT_ID), &apos;-&apos;, AUDIT_COMPANY)"/>

  <xsl:key name="tpa" match="*" use="concat(concat(concat(REPORT_TYPE, &apos;-&apos;, VISIT_ID), &apos;-&apos;, AUDIT_COMPANY), &apos;-&apos;, TPA_AUDITOR)"/>

  <xsl:key name="asg" match="*" use="concat(concat(concat(concat(REPORT_TYPE, &apos;-&apos;, VISIT_ID), &apos;-&apos;, AUDIT_COMPANY), &apos;-&apos;, TPA_AUDITOR), &apos;-&apos;, ASSIGNMENTS)"/>

 

 

  <xsl:template match="/">

        <xsl:apply-templates select="ROWSET"/>

    </xsl:template>

   

    <xsl:template match="/ROWSET">

        <xsl:variable name="RT" select="REPORT_TYPE"></xsl:variable>

       <xsl:for-each select="*[generate-id() = generate-id(key(&apos;vst&apos;, concat(REPORT_TYPE, &apos;-&apos;, VISIT_ID))[1])]">

            <xsl:if test="not(position() = 1)">

            <xsl:text>,</xsl:text>

            </xsl:if>

      "<xsl:value-of select="REPORT_TYPE"/>":[

      {

        <xsl:apply-templates select="*" mode="inner"/>,

    

   "AUDIT_COMPANIES":[

        <xsl:variable name="RT" select="REPORT_TYPE"></xsl:variable>

        <xsl:variable name="VI" select="VISIT_ID"></xsl:variable>

        <xsl:for-each select="../*[generate-id() = generate-id(key(&apos;cmp&apos;, concat(concat($RT, &apos;-&apos;, $VI), &apos;-&apos;, AUDIT_COMPANY) )[1])]">

          <xsl:if test="position() &gt; 1">

             <xsl:text>,</xsl:text>

             <xsl:text>&#10;</xsl:text>

        </xsl:if>

          {

      <xsl:apply-templates select="AUDIT_COMPANY" mode="grouped-cmp"/>

     

       <xsl:apply-templates select="*" mode="grouped-cmp"/>,

      "AUDITORS":[

        <xsl:variable name="RT" select="REPORT_TYPE"></xsl:variable>

        <xsl:variable name="VI" select="VISIT_ID"></xsl:variable>

        <xsl:variable name="AC" select="AUDIT_COMPANY"></xsl:variable>

    <xsl:for-each select="../*[generate-id() = generate-id(key(&apos;tpa&apos;, concat(concat(concat($RT, &apos;-&apos;, $VI), &apos;-&apos;, $AC), &apos;-&apos;, TPA_AUDITOR))[1])]">

          <xsl:if test="position() &gt; 1">

             <xsl:text>,</xsl:text>

             <xsl:text>&#10;</xsl:text>

        </xsl:if>

          {

          <xsl:apply-templates select="*" mode="grouped-tpa"/>,

              "ASSIGNMENTS":[

              <xsl:variable name="RT" select="REPORT_TYPE"></xsl:variable>

        <xsl:variable name="VI" select="VISIT_ID"></xsl:variable>

              <xsl:variable name="AC" select="AUDIT_COMPANY"></xsl:variable>

              <xsl:variable name="TA" select="TPA_AUDITOR"></xsl:variable>

              <xsl:for-each select="../*[generate-id() = generate-id(key(&apos;asg&apos;, concat(concat(concat(concat($RT, &apos;-&apos;, $VI), &apos;-&apos;, $AC), &apos;-&apos;, $TA), &apos;-&apos;, ASSIGNMENTS) )[1])]">

                <xsl:if test="position() &gt; 1">

                   <xsl:text>,</xsl:text>

                   <xsl:text>&#10;</xsl:text>

                </xsl:if>

                {

                <xsl:apply-templates select="*" mode="grouped-asg"/>

                }

              </xsl:for-each>

            ]

          }

        </xsl:for-each>

        ]

      }

        </xsl:for-each>

     ]

    }

       ]

        </xsl:for-each>

        }

    </xsl:template>

   

  

    <xsl:template match="*" mode="inner">

        <xsl:if test="position() &gt; 1 and position() &lt; 34">

      <xsl:text>,</xsl:text>

      <xsl:text>&#10;</xsl:text>

        </xsl:if>

    <xsl:if test="position()&lt;34">

      <xsl:text>"</xsl:text>

     

      <xsl:value-of select="name()"/>

      <xsl:text>":"</xsl:text>

      <xsl:value-of select="text()"/>

      <xsl:text>"</xsl:text>

        </xsl:if>

    </xsl:template>

 

      <xsl:template match="*" mode="grouped-cmp">

      <xsl:if test="position()=34">

      <xsl:text>"</xsl:text>

      <xsl:value-of select="name()"/>

      <xsl:text>":"</xsl:text>

      <xsl:value-of select="text()"/>

      <xsl:text>"</xsl:text>

      </xsl:if>

    </xsl:template>

   

    <xsl:template match="*" mode="grouped-tpa">

      <xsl:if test="position() = 36">

        <xsl:text>,</xsl:text>

        <xsl:text>&#10;</xsl:text>

      </xsl:if>

      <xsl:if test="position()&gt;34 and position()&lt;37">

      <xsl:text>"</xsl:text>

      <xsl:value-of select="name()"/>

      <xsl:text>":"</xsl:text>

      <xsl:value-of select="text()"/>

      <xsl:text>"</xsl:text>

      </xsl:if>

    </xsl:template>

   

    <xsl:template match="*" mode="grouped-asg">

      <xsl:if test="position() = 37">

            <xsl:text>"</xsl:text>

            <xsl:value-of select="name()"/>

            <xsl:text>":"</xsl:text>

            <xsl:value-of select="text()"/>

            <xsl:text>"</xsl:text>

      </xsl:if>

    </xsl:template>

    </xsl:stylesheet>';

Thanks

Dillip

This discussion has been closed.