Correct my xslt for data substitution
hi experts,
I have xhtml file as 1 node in my xml and data as 1 node in the same xml.
I am trying to add attribute value in all text fields of html using data present in xml.
<Main>
<Errored>
<StudentRecord>......................</StudentRecord>
<StudentRecord>.....................</StudentRecord>
<StudentRecord>.....................</StudentRecord>
<StudentRecord>.....................</StudentRecord>
</Errored>
<FileData>
<html>........................</html>
</FileData>
My input xml for html has many studentrecord nodes but i have to substitite the value of matching SSN number record only.
i have xslt code substituting 1 record but it is not working if i add check for SSN number since there is conflict of nodes i guess.I think apply-templates will help but i am not very good in applying templates.Please correct my xslt.
I am displaying all the errors in particular student record on top of my html and it is working fine.I have error attribute in each element og Student Record with proper message if the child data is not correct.
Here is my xslt
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<Main>
<Data type="">
<xsl:apply-templates/>
</Data>
</Main>
</xsl:template>
<xsl:template match="@* | node()[ancestor-or-self::FileData[@fileName='Student.html']/html]">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="node()[not(ancestor-or-self::FileData[@fileName='Student.html']/html)]">
<xsl:apply-templates select="node()"/>
</xsl:template>
<xsl:template match="//table[@id='error']">
<xsl:param name="StudentSSN" select="'345355353'"/>
<xsl:param name="StudentKey" select="'StudentPin345'"/>
<xsl:param name="StudentPin" select="'2619345'"/>
<table id="error">
<tr class="errorText">
<xsl:if test="count(//Errored/*)>0">
<xsl:for-each select="//Errored/StudentRecord//*">
<xsl:if test ="SSN=$StudentSSN or Student_PIN=$StudentPin or Local_Student_Key=$StudentKey" >
<xsl:apply-templates/>
</xsl:if>
</xsl:for-each>
</xsl:if>
</tr>
</table>
</xsl:template>
<xsl:template match="//Errored/StudentRecord//*">
<xsl:if test="''!=@error">
<td >
<xsl:value-of select="@error"/>
</td>
</xsl:if>
</xsl:template>
<xsl:template match="//input[@type='text']">
<xsl:param name="StudentSSN" select="'345355353'"/>
<xsl:param name="StudentKey" select="'StudentPin345'"/>
<xsl:param name="StudentPin" select="'2619345'"/>
<xsl:for-each select="//Errored/StudentRecord//*">
<xsl:if test="SSN=$StudentSSN">
<xsl:apply-templates/>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="//input[@type='text']">
<input>
<xsl:copy-of select="@*"/>
<xsl:attribute name="value">
<xsl:if test="@name='SchoolID'">
<xsl:value-of select="'LAURA'"/>
</xsl:if>
</xsl:attribute>
</input>
</xsl:template>
</xsl:stylesheet>
Instead of LAURA i want to pass data from studentrecord xml where SSN=?
Please correct my xslt
Thanks
|