EDN Admin
Well-known member
I have an XML
<?xml version="1.0" encoding="utf-8"?>
<School>
<Name>MHSS</Name>
<Address>Add1</Address>
<Line1>Line1</Line1>
<Pincode>1800525</Pincode>
<StudentDetails>
<StudentDetail>
<AdmissionNumber>123</AdmissionNumber>
<FName>AAA</FName>
<LName>AAA</LName>
<Class>BBB</Class>
<Age>12</Age>
</StudentDetail>
<StudentDetail>
<AdmissionNumber>456</AdmissionNumber>
<FName>CCC</FName>
<LName>DDD</LName>
<Class>EEE</Class>
<Age>13</Age>
</StudentDetail>
<StudentDetail>
<AdmissionNumber>789</AdmissionNumber>
<FName>FFF</FName>
<LName>GGG</LName>
<Class>HHH</Class>
<Age>14</Age>
</StudentDetail>
</StudentDetails>
</School>
I have an XSLT
<xsl:template match="/
<SchoolDetail>
<SchoolHeader>
<xsl:attribute name="Name
<xsl:value-of select="./School/Name/text()"/>
</xsl:attribute>
<xsl:for-each select="./School/StudentDetails/StudentDetail
<xsl:variable name ="AdNo" select ="./AdmissionNumber/text() </xsl:variable>
<xsl:if test="$AdNo = 789
<StudentDetailss>
<xsl:element name="FName
<xsl:value-of select="./FName/text()"/>
</xsl:element>
<xsl:element name="ProductTitle
<xsl:value-of select="./LName/text()"/>
</xsl:element>
<xsl:element name="RateCode
<xsl:value-of select="./AdmissionNumber/text()"/>
</xsl:element>
</StudentDetailss>
</xsl:if>
<xsl:if test = "$AdNo != 789
<StudentDetailss>
<xsl:attribute name ="Value
<xsl:value-of select="Nil"/>
</xsl:attribute>
</StudentDetailss>
</xsl:if>
</xsl:for-each>
</SchoolHeader>
</SchoolDetail>
</xsl:template>
The Resulting XML is
<SchoolDetail>
<SchoolHeader Name="MHSS
<SchoolDetail Value="Nil" />
<SchoolDetail Value="Nil" />
<StudentDetailss>
<FName>FFF</FName>
<ProductTitle>GGG</ProductTitle>
<RateCode>789</RateCode>
</StudentDetailss>
</SchoolHeader>
</SchoolDetail>
If the Admission Number is matched it has to display the corresponding details of a student if not nil value has to be displayed.
but here, the nil value is getting displayed until the condition becomes true.
In XSLT, We cannot change the Variable value. I wanted to know, how can i set up a flag inside the Foreach loop for this scenario.
Kindly Provide me with the solution
Vignesh S ----------------------------------------------------------- Please use Mark as Answer if my post has solved your problem and use Vote As Helpful if my post was useful.
View the full article
<?xml version="1.0" encoding="utf-8"?>
<School>
<Name>MHSS</Name>
<Address>Add1</Address>
<Line1>Line1</Line1>
<Pincode>1800525</Pincode>
<StudentDetails>
<StudentDetail>
<AdmissionNumber>123</AdmissionNumber>
<FName>AAA</FName>
<LName>AAA</LName>
<Class>BBB</Class>
<Age>12</Age>
</StudentDetail>
<StudentDetail>
<AdmissionNumber>456</AdmissionNumber>
<FName>CCC</FName>
<LName>DDD</LName>
<Class>EEE</Class>
<Age>13</Age>
</StudentDetail>
<StudentDetail>
<AdmissionNumber>789</AdmissionNumber>
<FName>FFF</FName>
<LName>GGG</LName>
<Class>HHH</Class>
<Age>14</Age>
</StudentDetail>
</StudentDetails>
</School>
I have an XSLT
<xsl:template match="/
<SchoolDetail>
<SchoolHeader>
<xsl:attribute name="Name
<xsl:value-of select="./School/Name/text()"/>
</xsl:attribute>
<xsl:for-each select="./School/StudentDetails/StudentDetail
<xsl:variable name ="AdNo" select ="./AdmissionNumber/text() </xsl:variable>
<xsl:if test="$AdNo = 789
<StudentDetailss>
<xsl:element name="FName
<xsl:value-of select="./FName/text()"/>
</xsl:element>
<xsl:element name="ProductTitle
<xsl:value-of select="./LName/text()"/>
</xsl:element>
<xsl:element name="RateCode
<xsl:value-of select="./AdmissionNumber/text()"/>
</xsl:element>
</StudentDetailss>
</xsl:if>
<xsl:if test = "$AdNo != 789
<StudentDetailss>
<xsl:attribute name ="Value
<xsl:value-of select="Nil"/>
</xsl:attribute>
</StudentDetailss>
</xsl:if>
</xsl:for-each>
</SchoolHeader>
</SchoolDetail>
</xsl:template>
The Resulting XML is
<SchoolDetail>
<SchoolHeader Name="MHSS
<SchoolDetail Value="Nil" />
<SchoolDetail Value="Nil" />
<StudentDetailss>
<FName>FFF</FName>
<ProductTitle>GGG</ProductTitle>
<RateCode>789</RateCode>
</StudentDetailss>
</SchoolHeader>
</SchoolDetail>
If the Admission Number is matched it has to display the corresponding details of a student if not nil value has to be displayed.
but here, the nil value is getting displayed until the condition becomes true.
In XSLT, We cannot change the Variable value. I wanted to know, how can i set up a flag inside the Foreach loop for this scenario.
Kindly Provide me with the solution
Vignesh S ----------------------------------------------------------- Please use Mark as Answer if my post has solved your problem and use Vote As Helpful if my post was useful.
View the full article