Jump to content

Parsing XML using XSLT with loop

- - - - -

  • Please log in to reply
No replies to this topic

#1
zedric001

zedric001

    Newbie

  • Members
  • Pip
  • 1 posts
I'm parsing an XML document and I have a nested for-each loop.

here's the XML document:


<ProgramKPI>

  <KPIs>

    <KPI_ID>1</KPI_ID>

    <Attribute>    BEHAVIOR</Attribute>

    <AttributeCode />

    <ControlType>0</ControlType>

    <Parent_KPI>0</Parent_KPI>

    <DisplayOrder>1</DisplayOrder>

    <isActive>1</isActive>

    <Level>1</Level>

  </KPIs>

  <KPIs>

    <KPI_ID>2</KPI_ID>

    <Attribute>        Company KPIs</Attribute>

    <Parent_KPI>1</Parent_KPI>

    <DisplayOrder>1</DisplayOrder>

    <isActive>1</isActive>

    <Level>2</Level>

  </KPIs>

  <KPIs>

    <KPI_ID>3</KPI_ID>

    <Attribute>            Customer Demeanor at Start of call:</Attribute>

    <Parent_KPI>2</Parent_KPI>

    <DisplayOrder>1</DisplayOrder>

    <isActive>1</isActive>

    <Level>3</Level>

  </KPIs>

  <KPIs>

    <KPI_ID>4</KPI_ID>

    <Attribute>                Audibly Happy</Attribute>

    <AttributeCode>A</AttributeCode>

    <ControlType>1</ControlType>

    <Parent_KPI>3</Parent_KPI>

    <DisplayOrder>1</DisplayOrder>

    <isActive>1</isActive>

    <Level>4</Level>

  </KPIs>

  <KPIs>

    <KPI_ID>5</KPI_ID>

    <Attribute>                Neutral</Attribute>

    <AttributeCode>N</AttributeCode>

    <ControlType>1</ControlType>

    <Parent_KPI>3</Parent_KPI>

    <DisplayOrder>2</DisplayOrder>

    <isActive>1</isActive>

    <Level>4</Level>

  </KPIs>

  <KPIs>

    <KPI_ID>6</KPI_ID>

    <Attribute>                Irate</Attribute>

    <AttributeCode>I</AttributeCode>

    <ControlType>1</ControlType>

    <Parent_KPI>3</Parent_KPI>

    <DisplayOrder>3</DisplayOrder>

    <isActive>1</isActive>

    <Level>4</Level>

  </KPIs>

  <KPIs>

    <KPI_ID>7</KPI_ID>

    <Attribute>                At risk</Attribute>

    <AttributeCode>R</AttributeCode>

    <ControlType>1</ControlType>

    <Parent_KPI>3</Parent_KPI>

    <DisplayOrder>4</DisplayOrder>

    <isActive>1</isActive>

    <Level>4</Level>

  </KPIs>

  <KPIs>

  <KPIs>

    <KPI_ID>38</KPI_ID>

    <Attribute>            Resulted in a Sale</Attribute>

    <Parent_KPI>2</Parent_KPI>

    <DisplayOrder>10</DisplayOrder>

    <isActive>1</isActive>

    <Level>3</Level>

  </KPIs>

  <KPIs>

    <KPI_ID>39</KPI_ID>

    <Attribute>                Yes</Attribute>

    <AttributeCode>Y</AttributeCode>

    <ControlType>1</ControlType>

    <Parent_KPI>38</Parent_KPI>

    <DisplayOrder>1</DisplayOrder>

    <isActive>1</isActive>

    <Level>4</Level>

  </KPIs>

  <KPIs>

    <KPI_ID>40</KPI_ID>

    <Attribute>                No</Attribute>

    <AttributeCode>N</AttributeCode>

    <ControlType>1</ControlType>

    <Parent_KPI>38</Parent_KPI>

    <DisplayOrder>2</DisplayOrder>

    <isActive>1</isActive>

    <Level>4</Level>

  </KPIs>

  <KPIs>

    <KPI_ID>41</KPI_ID>

    <Attribute>                NA</Attribute>

    <AttributeCode>NA</AttributeCode>

    <ControlType>1</ControlType>

    <Parent_KPI>38</Parent_KPI>

    <DisplayOrder>3</DisplayOrder>

    <isActive>1</isActive>

    <Level>4</Level>

  </KPIs>

</ProgramKPI>


this is the XSLT code:


<xsl:template match="/">

      <table>

        <xsl:for-each select="ProgramKPI/KPIs">

            <xsl:choose>

              

              <xsl:when test="Level = '1'">

              <tr>

              <td>

                <xsl:value-of select="Attribute"/>

              </td>

              </tr>

              </xsl:when>

              

              <xsl:when test="Level = '2'">

                <tr>

                <td>

                  <xsl:value-of select="Attribute"/>

                </td>

                </tr>

              </xsl:when>

              

              <xsl:when test="Level = '3'">

                

                <tr>

                <td>

                  <xsl:value-of select="Attribute"/>

                </td>

                  

                <xsl:variable name="varKPI" select="KPI_ID" />

                  

                <td>

                  <select id="{concat('ddl_', KPI_ID)}" >

                    

                    <option value="0">  Select  

                    </option>

</select>

                </td>

                </tr>

                

              </xsl:when>

              

            </xsl:choose>

        </xsl:for-each>

      </table>

</xsl:template>



running these codes will show the list of KPIs (Key Performance Indicators) with the dropdownlist items (option) in each Level 3 Attribute.

what I want to achieve is to add options on the dropdownlist items. The options will be coming from the same XML file where Level = 4 and Parent_KPI = [current] KPI. How can it be possible?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users