I have a scenario where I am trying to assign value to a variable dynamically, could you please tell me how I can achieve this.
In the below XML sample, I loop through Content2 and read the values of attributes from Content1
like
<xsl:variable name="var1" select="//XMLContent/CONTENT1/DATA/CHILD[4]/@PName1"/>
This is fine.
I am not sure how I can dynmacially retrieve the attribute names from Child4 for Content1.
I was trying something like this in the forloop(below) that I have within a main for-each loop; please only cosider the two variables below; (for-each loop is only for understanding on how I am getting the attribute name.)
<xsl:for-each select="@*">
<xsl:variable name="attName" select="name()"/>
<xsl:variable name="var1" select="concat('//XMLContent/CONTENT1/DATA/CHILD[4]/@',$attName"/>
</xsl:for-each>
The problem is, I need to have a for-each loop and I need to get this value dynamically, there are lot of other process I am trying to achieve in the loop, which is not explained here. This is very critical for me, any answers will be of great help.
<XMLContent><CONTENT1>
<DATA PRJTID="217" REGID="F_DATA">
<CHILD PNUM="" PKID="" PKID1="" PKID2="" PName1="" PName2="" P_DOMFOR="" DP1="" DP2=""/>
<CHILD PNUM="" PKID="" PKID1="" PKID2="" PName1="" PName2="" P_DOMFOR="" DP1="" DP2=""/>
<CHILD PNUM="" PKID="" PKID1="" PKID2="" PName1="" PName2="" P_DOMFOR="" DP1="" DP2=""/>
<CHILD PNUM="P No" PKID="P Key ID" PName1="Name Line 1" PName2="Name Line 2" P_DOMFOR="Domestic" />
<CHILD PNUM="ROUNDING VAL" PKID="" PKID2="" PName1="TOTALS" PName2="" P_DOMFOR="" DP1="" DP2=""/>
<CHILD PNUM="1" PKID="1" PKID1="" PKID2="" PName1="Name Line 1a" PName2="Name Line 1b"
P_DOMFOR="Domestic" DP1="10" DP2="20"/>
<CHILD PNUM="2" PKID="2" PKID1="" PKID2="" PName1="Name Line 2a" PName2="" P_DOMFOR="Foreign"
DP1="100" DP2="200"/>
<CHILD PNUM="3" PKID="3" PKID1="" PKID2="" PName1="First Middle Last" PName2="" P_DOMFOR="Domestic"
DP1="1000" DP2="2000"/>
</DATA></CONTENT1>
<CONTENT2>
<DATA PRJTID="217" REGID="PDI">
<CHILD PNUM="1" PKID="" PKID1="" PKID2="" PName1="" PName2="" PName3="" PAdd1="" PAdd2="" PCity=""
PID="Form" />
<CHILD PNUM="" PKID="" PKID1="" PKID2="" PName1="" PName2="" PName3="" PAdd1="" PAdd2="" PCity=""
PID="Line" />
<CHILD PNUM="" PKID="" PKID1="" PKID2="" PName1="" PName2="" PName3="" PAdd1="" PAdd2="" PCity=""
PID="Code" />
<CHILD PNUM="P No" PKID="PKey ID" PKID1="Other ID" PKID2="Other ID - 2" PName1="P Name Line 1"
PName2="P Name PAdd1="Street Address 1" PAdd2="Street Address 2" PCity="City" PID=""/>
<CHILD PNUM="" PKID="PDetails" PKID1="" PKID2="" PName1="" PName2="" PName3="" PAdd1="" PAdd2=""
PCity="" PTD_USFORIND="" PTDI_ADDST="" PTDI_ADDZIP="" PID="Fund" PTDI_CUST5="" />
<CHILD PNUM="1" PKID="1" PKID1="" PKID2="" PName1=" Name Line 1# " PName2="Name Line 1b" PName3=""
PAdd1=" 1 Mai$n S.t" PAdd2="Apt 1" PCity="NewCity" PID="1" />
<CHILD PNUM="2" PKID="2" PKID1="" PKID2="" PName1="Name Line 2a" PName2="" PName3="" PAdd1="2 Main St"
PAdd2="" PCity="Berlin" PID="2" />
<CHILD PNUM="3" PKID="3" PKID1="" PKID2="" PName1="First Middle Last" PName2="" PName3="" PAdd1="3
Main St" PAdd2="" PCity="Los Angeles" PID="3" />
</DATA></CONTENT2></XMLContent>
Rpaul