Home > Back-end >  XSLT Template Looping Records
XSLT Template Looping Records

Time:04-29

I am working on a requirement to build a xsl tempalte with a loop a position record to print multiple times depending on a vacant positions numbers availabe in each record. I am completely new to this code and created a draft template to print the records. But I am not able to add the loops into this.

Eg: Current text output:

PositionIdentifier,Position Name,Grade Name,Vacant Positions
1365,Data Processing Manager,M,2

Expected text output:

PositionIdentifier,Position Name,Grade Name,Vacant Positions
1365,Data Processing Manager,M,Vacant1
1365,Data Processing Manager,M,Vacant2

[enter image description here][1]

Request your help to complete this code. Please let me know if you need any further information.

Regards, Murali

XML code below:

    <?xml version = '1.0' encoding = 'utf-8'?>
<!--Generated by Oracle BI Publisher -Dataengine, datamodel:_Custom_Human_Capital_Management_Payroll_Data_Models_STL_I_EPM_107_B___Vacant_Positions_Demographics_DM_xdm -->
<DATA_DS><P_DATE>2022-04-19T00:00:00.000 00:00</P_DATE>
<G_1>
<FISCALYEAR>FY22</FISCALYEAR><POSITIONID>1541</POSITIONID><POSITION_NAME>Test Benefits Clerk</POSITION_NAME><GRADE_NAME>G</GRADE_NAME><PAYPERIOD_END_DATE>04/23/2022</PAYPERIOD_END_DATE><PAY_PERIOD>22</PAY_PERIOD><MONTHS>APR</MONTHS><NO_OF_PAYS>26</NO_OF_PAYS><FILLED_FTE>1</FILLED_FTE><VACANT_POSITIONS>1</VACANT_POSITIONS><EMPLOYEE_ID>Vacant</EMPLOYEE_ID><NAME>1541 Benefits Clerk</NAME>
</G_1>
<G_1>
<FISCALYEAR>FY22</FISCALYEAR><POSITIONID>1122</POSITIONID><POSITION_NAME>Test Clerk Typist                  </POSITION_NAME><GRADE_NAME>G</GRADE_NAME><PAYPERIOD_END_DATE>04/23/2022</PAYPERIOD_END_DATE><PAY_PERIOD>22</PAY_PERIOD><MONTHS>APR</MONTHS><NO_OF_PAYS>26</NO_OF_PAYS><FILLED_FTE>1</FILLED_FTE><VACANT_POSITIONS>2</VACANT_POSITIONS><EMPLOYEE_ID>Vacant</EMPLOYEE_ID><NAME>1122 Clerk Typist</NAME>
</G_1>
<G_1>
<FISCALYEAR>FY22</FISCALYEAR><POSITIONID>1513</POSITIONID><POSITION_NAME>Test Human Resources Specialist I  </POSITION_NAME><GRADE_NAME>G</GRADE_NAME><PAYPERIOD_END_DATE>04/23/2022</PAYPERIOD_END_DATE><PAY_PERIOD>22</PAY_PERIOD><MONTHS>APR</MONTHS><NO_OF_PAYS>26</NO_OF_PAYS><FILLED_FTE>2</FILLED_FTE><VACANT_POSITIONS>1</VACANT_POSITIONS><EMPLOYEE_ID>Vacant</EMPLOYEE_ID><NAME>1513 Human Resources Specialist I</NAME>
</G_1>
<G_1>
<FISCALYEAR>FY22</FISCALYEAR><POSITIONID>1514</POSITIONID><POSITION_NAME>Test Human Resources Specialist II </POSITION_NAME><GRADE_NAME>G</GRADE_NAME><PAYPERIOD_END_DATE>04/23/2022</PAYPERIOD_END_DATE><PAY_PERIOD>22</PAY_PERIOD><MONTHS>APR</MONTHS><NO_OF_PAYS>26</NO_OF_PAYS><FILLED_FTE>1</FILLED_FTE><VACANT_POSITIONS>1</VACANT_POSITIONS><EMPLOYEE_ID>Vacant</EMPLOYEE_ID><NAME>1514 Human Resources Specialist II</NAME>
</G_1>
<G_1>
<FISCALYEAR>FY22</FISCALYEAR><POSITIONID>1332</POSITIONID><POSITION_NAME>Test Computer Programmer II</POSITION_NAME><GRADE_NAME>G</GRADE_NAME><PAYPERIOD_END_DATE>04/23/2022</PAYPERIOD_END_DATE><PAY_PERIOD>22</PAY_PERIOD><MONTHS>APR</MONTHS><NO_OF_PAYS>26</NO_OF_PAYS><FILLED_FTE>1</FILLED_FTE><VACANT_POSITIONS>1</VACANT_POSITIONS><EMPLOYEE_ID>Vacant</EMPLOYEE_ID><NAME>1332 Computer Programmer II</NAME>
</G_1>
<G_1>
<FISCALYEAR>FY22</FISCALYEAR><POSITIONID>1352</POSITIONID><POSITION_NAME>Test Systems Project Leader        </POSITION_NAME><GRADE_NAME>M</GRADE_NAME><PAYPERIOD_END_DATE>04/23/2022</PAYPERIOD_END_DATE><PAY_PERIOD>22</PAY_PERIOD><MONTHS>APR</MONTHS><NO_OF_PAYS>26</NO_OF_PAYS><FILLED_FTE>3</FILLED_FTE><VACANT_POSITIONS>2</VACANT_POSITIONS><EMPLOYEE_ID>Vacant</EMPLOYEE_ID><NAME>1352 Systems Project Leader</NAME>
</G_1>
<G_1>
<FISCALYEAR>FY22</FISCALYEAR><POSITIONID>1371</POSITIONID><POSITION_NAME>Test Technical Support Specialist I</POSITION_NAME><GRADE_NAME>G</GRADE_NAME><PAYPERIOD_END_DATE>04/23/2022</PAYPERIOD_END_DATE><PAY_PERIOD>22</PAY_PERIOD><MONTHS>APR</MONTHS><NO_OF_PAYS>26</NO_OF_PAYS><FILLED_FTE>4</FILLED_FTE><VACANT_POSITIONS>2</VACANT_POSITIONS><EMPLOYEE_ID>Vacant</EMPLOYEE_ID><NAME>127 Technical Support Specialist I</NAME>
</G_1>
<G_1>
<FISCALYEAR>FY22</FISCALYEAR><POSITIONID>3518</POSITIONID><POSITION_NAME>Test Water Maintenance Technician</POSITION_NAME><GRADE_NAME>G</GRADE_NAME><PAYPERIOD_END_DATE>04/23/2022</PAYPERIOD_END_DATE><PAY_PERIOD>22</PAY_PERIOD><MONTHS>APR</MONTHS><NO_OF_PAYS>26</NO_OF_PAYS><FILLED_FTE>7</FILLED_FTE><VACANT_POSITIONS>73</VACANT_POSITIONS><EMPLOYEE_ID>Vacant</EMPLOYEE_ID><NAME>WtrDist-DistC-3518 Water Maintenance Technician</NAME>
</G_1>
<G_1>
<FISCALYEAR>FY22</FISCALYEAR><POSITIONID>1116</POSITIONID><POSITION_NAME>Test Customer Service Rep I        </POSITION_NAME><GRADE_NAME>G</GRADE_NAME><PAYPERIOD_END_DATE>04/23/2022</PAYPERIOD_END_DATE><PAY_PERIOD>22</PAY_PERIOD><MONTHS>APR</MONTHS><NO_OF_PAYS>26</NO_OF_PAYS><FILLED_FTE>1</FILLED_FTE><VACANT_POSITIONS>14</VACANT_POSITIONS><EMPLOYEE_ID>Vacant</EMPLOYEE_ID><NAME>Engnr-1116 Customer Service Representative I</NAME>
</G_1>
<G_1>
<FISCALYEAR>FY22</FISCALYEAR><POSITIONID>1142</POSITIONID><POSITION_NAME>Test Account Clerk II              </POSITION_NAME><GRADE_NAME>G</GRADE_NAME><PAYPERIOD_END_DATE>04/23/2022</PAYPERIOD_END_DATE><PAY_PERIOD>22</PAY_PERIOD><MONTHS>APR</MONTHS><NO_OF_PAYS>26</NO_OF_PAYS><FILLED_FTE>3</FILLED_FTE><VACANT_POSITIONS>2</VACANT_POSITIONS><EMPLOYEE_ID>Vacant</EMPLOYEE_ID><NAME>Account Clerk</NAME>
</G_1>
<G_1>
<FISCALYEAR>FY22</FISCALYEAR><POSITIONID>4241</POSITIONID><POSITION_NAME>Test Civil Engineer I</POSITION_NAME><GRADE_NAME>G</GRADE_NAME><PAYPERIOD_END_DATE>04/23/2022</PAYPERIOD_END_DATE><PAY_PERIOD>22</PAY_PERIOD><MONTHS>APR</MONTHS><NO_OF_PAYS>26</NO_OF_PAYS><FILLED_FTE>2</FILLED_FTE><VACANT_POSITIONS>1</VACANT_POSITIONS><EMPLOYEE_ID>Vacant</EMPLOYEE_ID><NAME>WtrDist-Engnr-4241 Civil Engineer I</NAME>
</G_1>
<G_1>
<FISCALYEAR>FY22</FISCALYEAR><POSITIONID>3517</POSITIONID><POSITION_NAME>Test Water Maintenance Foreman</POSITION_NAME><GRADE_NAME>G</GRADE_NAME><PAYPERIOD_END_DATE>04/23/2022</PAYPERIOD_END_DATE><PAY_PERIOD>22</PAY_PERIOD><MONTHS>APR</MONTHS><NO_OF_PAYS>26</NO_OF_PAYS><FILLED_FTE>2</FILLED_FTE><VACANT_POSITIONS>20</VACANT_POSITIONS><EMPLOYEE_ID>Vacant</EMPLOYEE_ID><NAME>WtrDist-Mtr Tap-3517 Water Maintenance Foreman</NAME>
</G_1>
</DATA_DS>

Tried to post the Sample XSL code but getting error while posting here. The sample output already shared on the top of the summary.

Please find the XSL code:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:functx="http://my/functions"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
    <xsl:output method="text" encoding="UTF-8"/>
    <xsl:variable name="csvDelimiter">,</xsl:variable>
    <xsl:param name="br">
        <xsl:text>&#xD;&#xa;</xsl:text>
    </xsl:param>
    <xsl:template match="/">
        <!-- ============================================================================== -->
        <!-- Printing headers 1 -->
        <!-- ============================================================================== -->
        <xsl:text>PositionIdentifier</xsl:text>
        <xsl:value-of select="$csvDelimiter"/>
        <xsl:text>Position Name</xsl:text>
        <xsl:value-of select="$csvDelimiter"/>
        <xsl:text>Grade Name</xsl:text>
        <xsl:value-of select="$csvDelimiter"/>
        <xsl:text>Vacant Positions</xsl:text>
        <!-- ======================================= -->
        <!-- Printing rows. -->
        <!-- ======================================= -->
        <xsl:for-each select ="/DATA_DS/G_1">
            <!-- Variables -->
            <xsl:variable name="POSITIONID">
                <xsl:value-of select="(POSITIONID)"/>
            </xsl:variable>
            <xsl:variable name="POSITION_NAME">
                <xsl:value-of select="(POSITION_NAME)"/>
            </xsl:variable>
            <xsl:variable name="GRADE_NAME">
                <xsl:value-of select="(GRADE_NAME)"/>
            </xsl:variable>
            <xsl:variable name="VACANT_POSITIONS">
                <xsl:value-of select="(VACANT_POSITIONS)"/>
            </xsl:variable>
            <xsl:value-of select="$br" />
            <!-- End Of Variables -->
            <xsl:value-of select="POSITIONID"/>
            <xsl:value-of select="$csvDelimiter"/>
            <xsl:value-of select="$POSITION_NAME"/>
            <xsl:value-of select="$csvDelimiter"/>
            <xsl:value-of select="$GRADE_NAME"/>
            <xsl:value-of select="$csvDelimiter"/>
            <xsl:value-of select="$VACANT_POSITIONS"/>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

CodePudding user response:

Your output does not match your input. There is no Data Processing Manager position in your input.

Assuming that the required output for the given input example is actually:

Result

PositionIdentifier,Position Name,Grade Name,Vacant Positions
1541,Test Benefits Clerk,G,VACANT1
1122,Test Clerk Typist,G,VACANT1
1122,Test Clerk Typist,G,VACANT2
1513,Test Human Resources Specialist I,G,VACANT1
1514,Test Human Resources Specialist II,G,VACANT1
1332,Test Computer Programmer II,G,VACANT1
1352,Test Systems Project Leader,M,VACANT1
1352,Test Systems Project Leader,M,VACANT2
1371,Test Technical Support Specialist I,G,VACANT1
1371,Test Technical Support Specialist I,G,VACANT2
3518,Test Water Maintenance Technician,G,VACANT1
3518,Test Water Maintenance Technician,G,VACANT2
3518,Test Water Maintenance Technician,G,VACANT3
3518,Test Water Maintenance Technician,G,VACANT4
3518,Test Water Maintenance Technician,G,VACANT5
3518,Test Water Maintenance Technician,G,VACANT6
3518,Test Water Maintenance Technician,G,VACANT7
3518,Test Water Maintenance Technician,G,VACANT8
3518,Test Water Maintenance Technician,G,VACANT9
3518,Test Water Maintenance Technician,G,VACANT10
3518,Test Water Maintenance Technician,G,VACANT11
3518,Test Water Maintenance Technician,G,VACANT12
3518,Test Water Maintenance Technician,G,VACANT13
3518,Test Water Maintenance Technician,G,VACANT14
3518,Test Water Maintenance Technician,G,VACANT15
3518,Test Water Maintenance Technician,G,VACANT16
3518,Test Water Maintenance Technician,G,VACANT17
3518,Test Water Maintenance Technician,G,VACANT18
3518,Test Water Maintenance Technician,G,VACANT19
3518,Test Water Maintenance Technician,G,VACANT20
3518,Test Water Maintenance Technician,G,VACANT21
3518,Test Water Maintenance Technician,G,VACANT22
3518,Test Water Maintenance Technician,G,VACANT23
3518,Test Water Maintenance Technician,G,VACANT24
3518,Test Water Maintenance Technician,G,VACANT25
3518,Test Water Maintenance Technician,G,VACANT26
3518,Test Water Maintenance Technician,G,VACANT27
3518,Test Water Maintenance Technician,G,VACANT28
3518,Test Water Maintenance Technician,G,VACANT29
3518,Test Water Maintenance Technician,G,VACANT30
3518,Test Water Maintenance Technician,G,VACANT31
3518,Test Water Maintenance Technician,G,VACANT32
3518,Test Water Maintenance Technician,G,VACANT33
3518,Test Water Maintenance Technician,G,VACANT34
3518,Test Water Maintenance Technician,G,VACANT35
3518,Test Water Maintenance Technician,G,VACANT36
3518,Test Water Maintenance Technician,G,VACANT37
3518,Test Water Maintenance Technician,G,VACANT38
3518,Test Water Maintenance Technician,G,VACANT39
3518,Test Water Maintenance Technician,G,VACANT40
3518,Test Water Maintenance Technician,G,VACANT41
3518,Test Water Maintenance Technician,G,VACANT42
3518,Test Water Maintenance Technician,G,VACANT43
3518,Test Water Maintenance Technician,G,VACANT44
3518,Test Water Maintenance Technician,G,VACANT45
3518,Test Water Maintenance Technician,G,VACANT46
3518,Test Water Maintenance Technician,G,VACANT47
3518,Test Water Maintenance Technician,G,VACANT48
3518,Test Water Maintenance Technician,G,VACANT49
3518,Test Water Maintenance Technician,G,VACANT50
3518,Test Water Maintenance Technician,G,VACANT51
3518,Test Water Maintenance Technician,G,VACANT52
3518,Test Water Maintenance Technician,G,VACANT53
3518,Test Water Maintenance Technician,G,VACANT54
3518,Test Water Maintenance Technician,G,VACANT55
3518,Test Water Maintenance Technician,G,VACANT56
3518,Test Water Maintenance Technician,G,VACANT57
3518,Test Water Maintenance Technician,G,VACANT58
3518,Test Water Maintenance Technician,G,VACANT59
3518,Test Water Maintenance Technician,G,VACANT60
3518,Test Water Maintenance Technician,G,VACANT61
3518,Test Water Maintenance Technician,G,VACANT62
3518,Test Water Maintenance Technician,G,VACANT63
3518,Test Water Maintenance Technician,G,VACANT64
3518,Test Water Maintenance Technician,G,VACANT65
3518,Test Water Maintenance Technician,G,VACANT66
3518,Test Water Maintenance Technician,G,VACANT67
3518,Test Water Maintenance Technician,G,VACANT68
3518,Test Water Maintenance Technician,G,VACANT69
3518,Test Water Maintenance Technician,G,VACANT70
3518,Test Water Maintenance Technician,G,VACANT71
3518,Test Water Maintenance Technician,G,VACANT72
3518,Test Water Maintenance Technician,G,VACANT73
1116,Test Customer Service Rep I,G,VACANT1
1116,Test Customer Service Rep I,G,VACANT2
1116,Test Customer Service Rep I,G,VACANT3
1116,Test Customer Service Rep I,G,VACANT4
1116,Test Customer Service Rep I,G,VACANT5
1116,Test Customer Service Rep I,G,VACANT6
1116,Test Customer Service Rep I,G,VACANT7
1116,Test Customer Service Rep I,G,VACANT8
1116,Test Customer Service Rep I,G,VACANT9
1116,Test Customer Service Rep I,G,VACANT10
1116,Test Customer Service Rep I,G,VACANT11
1116,Test Customer Service Rep I,G,VACANT12
1116,Test Customer Service Rep I,G,VACANT13
1116,Test Customer Service Rep I,G,VACANT14
1142,Test Account Clerk II,G,VACANT1
1142,Test Account Clerk II,G,VACANT2
4241,Test Civil Engineer I,G,VACANT1
3517,Test Water Maintenance Foreman,G,VACANT1
3517,Test Water Maintenance Foreman,G,VACANT2
3517,Test Water Maintenance Foreman,G,VACANT3
3517,Test Water Maintenance Foreman,G,VACANT4
3517,Test Water Maintenance Foreman,G,VACANT5
3517,Test Water Maintenance Foreman,G,VACANT6
3517,Test Water Maintenance Foreman,G,VACANT7
3517,Test Water Maintenance Foreman,G,VACANT8
3517,Test Water Maintenance Foreman,G,VACANT9
3517,Test Water Maintenance Foreman,G,VACANT10
3517,Test Water Maintenance Foreman,G,VACANT11
3517,Test Water Maintenance Foreman,G,VACANT12
3517,Test Water Maintenance Foreman,G,VACANT13
3517,Test Water Maintenance Foreman,G,VACANT14
3517,Test Water Maintenance Foreman,G,VACANT15
3517,Test Water Maintenance Foreman,G,VACANT16
3517,Test Water Maintenance Foreman,G,VACANT17
3517,Test Water Maintenance Foreman,G,VACANT18
3517,Test Water Maintenance Foreman,G,VACANT19
3517,Test Water Maintenance Foreman,G,VACANT20

it could be produced using:

XSLT 2.0

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

<xsl:template match="/DATA_DS">
    <!-- header -->
    <xsl:text>PositionIdentifier,Position Name,Grade Name,Vacant Positions&#xD;&#xa;</xsl:text>
    <!-- data -->   
    <xsl:for-each select="G_1">
        <xsl:variable name="common-data">
            <xsl:value-of select="POSITIONID"/>
            <xsl:text>,</xsl:text>
            <xsl:value-of select="normalize-space(POSITION_NAME)"/>
            <xsl:text>,</xsl:text>
            <xsl:value-of select="GRADE_NAME"/>
            <xsl:text>,</xsl:text>
        </xsl:variable>
        <xsl:for-each select="1 to VACANT_POSITIONS">
            <xsl:copy-of select="$common-data"/>
            <xsl:text>VACANT</xsl:text>
            <xsl:value-of select="."/>
            <xsl:text>&#xD;&#xa;</xsl:text>
        </xsl:for-each>
    </xsl:for-each> 
</xsl:template>

</xsl:stylesheet>
  • Related