on 10-10-2014 6:49 PM
Hi, all
I am stuck with the XSLT program that is supposed to fulfill the following requirement:
Source:
<DT_IN>
<DATA>
<PERNR>111</PERNR>
<PayRecord>
<WageType>A1</WageType>
<Hours>10</Hours>
</PayRecord>
<PayRecord>
<WageType>A2</WageType>
<Hours>15</Hours>
</PayRecord>
<PayPeriod>201402</PayPeriod>
</DATA>
<DATA>
<PERNR>222</PERNR>
<PayRecord>
<WageType>A3</WageType>
<Hours>100</Hours>
</PayRecord>
<PayRecord>
<WageType>A4</WageType>
<Hours>150</Hours>
</PayRecord>
<PayPeriod>201405</PayPeriod>
</DATA>
</DT_IN>
Output:
<?xml version="1.0" encoding="UTF-8"?>
<DT_IN>
<DATA>
<PERNR>111</PERNR>
<WageType>A1</WageType>
<Hours>10</Hours>
<Payperiod>201402</Payperiod>
</DATA>
<DATA>
<PERNR>111</PERNR>
<WageType>A2</WageType>
<Hours>15</Hours>
<Payperiod>201402</Payperiod>
</DATA>
<DATA>
<PERNR>222</PERNR>
<WageType>A3</WageType>
<Hours>100</Hours>
<Payperiod>201405</Payperiod>
</DATA>
<DATA>
<PERNR>222</PERNR>
<WageType>A4</WageType>
<Hours>150</Hours>
<Payperiod>201405</Payperiod>
</DATA>
</DT_IN>
I am using the following XSLT program:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="DT_IN/DATA">
<xsl:variable name="empid" select="PERNR"/>
<xsl:variable name="payperiod" select="PayPeriod"/>
<xsl:for-each select="PayRecord">
<DATA>
<PERNR>
<xsl:value-of select="$empid"/>
</PERNR>
<WageType>
<xsl:value-of select="WageType"/>
</WageType>
<Hours>
<xsl:value-of select="Hours"/>
</Hours>
<Payperiod>
<xsl:value-of select="$payperiod"/>
</Payperiod>
</DATA>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The program can only create up to the <DATA> level properly. However, I cannot figure out a way to create the <DT_IN> tag. Please help.
Thanks,
Jonathan.
Just resolved it. Here's the program if you are interested:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<DT_IN>
<xsl:apply-templates/>
</DT_IN>
</xsl:template>
<xsl:template match="DT_IN/DATA">
<xsl:variable name="empid" select="PERNR"/>
<xsl:variable name="payperiod" select="PayPeriod"/>
<xsl:for-each select="PayRecord">
<DATA>
<PERNR>
<xsl:value-of select="$empid"/>
</PERNR>
<WageType>
<xsl:value-of select="WageType"/>
</WageType>
<Hours>
<xsl:value-of select="Hours"/>
</Hours>
<Payperiod>
<xsl:value-of select="$payperiod"/>
</Payperiod>
</DATA>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.