Hello Experts,
I'm trying to convert an dynamic XML doc into HTML using XSLT.
In the example I have shown one form(form1)...B ut there could be multiple forms....names are unknown and each one could have o or more childforms .I want to display form1 as <th> element followed by attributes,then display Childform1 as header(if there is a child form) .See the XSl below.
Is there a way to check if form1 has childforms...so i could render them differently than children of form1.
Pls help.
<root>
<forms>
<form1 attr1= "p" attr2 = "q">
<childForm1>
<SOURCE_CD>17 </SOURCE_CD>
<MAIN_FORM_ID>0 0023</MAIN_FORM_ID>
<DISTRICT_CD>00 </DISTRICT_CD>
</childForm1>
<childForm2>
<SOURCE_CD>17 </SOURCE_CD>
<MAIN_FORM_ID>0 0023</MAIN_FORM_ID>
<DISTRICT_CD>00 </DISTRICT_CD>
</childForm2>
<childForm3>
<SOURCE_CD>17 </SOURCE_CD>
<MAIN_FORM_ID>0 0023</MAIN_FORM_ID>
<DISTRICT_CD>00 </DISTRICT_CD>
</childForm3>
<childForm4>
<SOURCE_CD>17 </SOURCE_CD>
<MAIN_FORM_ID>0 0023</MAIN_FORM_ID>
<DISTRICT_CD>00 </DISTRICT_CD>
</childForm4>
<INT_DCMT_ID>24 2563</INT_DCMT_ID>
<EXT_TP_ID>2142 01050</EXT_TP_ID>
<TAX_TYPE_CD>PI </TAX_TYPE_CD>
<TAX_SUB_TYPE_C D>01</TAX_SUB_TYPE_CD >
</form1>
</forms>
</root>
<xsl:template name="label-value">
<tr><th><xsl:va lue-of select="name()" /></th></tr>
<xsl:for-each select="@*">
<tr>
<td>@ <xsl:value-of select="name()" /></td>
<td><xsl:valu e-of select="." /></td>
</tr>
</xsl:for-each>
<xsl:for-each select="*">
<tr>
<td><xsl:valu e-of select="name()" /></td>
<td><xsl:valu e-of select="." /></td>
</tr>
</xsl:for-each>
</xsl:template>
<xsl:template match="forms">
<xsl:for-each select="*">
<xsl:call-template name="label-value" />
</xsl:for-each>
</xsl:template>
I'm trying to convert an dynamic XML doc into HTML using XSLT.
In the example I have shown one form(form1)...B ut there could be multiple forms....names are unknown and each one could have o or more childforms .I want to display form1 as <th> element followed by attributes,then display Childform1 as header(if there is a child form) .See the XSl below.
Is there a way to check if form1 has childforms...so i could render them differently than children of form1.
Pls help.
<root>
<forms>
<form1 attr1= "p" attr2 = "q">
<childForm1>
<SOURCE_CD>17 </SOURCE_CD>
<MAIN_FORM_ID>0 0023</MAIN_FORM_ID>
<DISTRICT_CD>00 </DISTRICT_CD>
</childForm1>
<childForm2>
<SOURCE_CD>17 </SOURCE_CD>
<MAIN_FORM_ID>0 0023</MAIN_FORM_ID>
<DISTRICT_CD>00 </DISTRICT_CD>
</childForm2>
<childForm3>
<SOURCE_CD>17 </SOURCE_CD>
<MAIN_FORM_ID>0 0023</MAIN_FORM_ID>
<DISTRICT_CD>00 </DISTRICT_CD>
</childForm3>
<childForm4>
<SOURCE_CD>17 </SOURCE_CD>
<MAIN_FORM_ID>0 0023</MAIN_FORM_ID>
<DISTRICT_CD>00 </DISTRICT_CD>
</childForm4>
<INT_DCMT_ID>24 2563</INT_DCMT_ID>
<EXT_TP_ID>2142 01050</EXT_TP_ID>
<TAX_TYPE_CD>PI </TAX_TYPE_CD>
<TAX_SUB_TYPE_C D>01</TAX_SUB_TYPE_CD >
</form1>
</forms>
</root>
<xsl:template name="label-value">
<tr><th><xsl:va lue-of select="name()" /></th></tr>
<xsl:for-each select="@*">
<tr>
<td>@ <xsl:value-of select="name()" /></td>
<td><xsl:valu e-of select="." /></td>
</tr>
</xsl:for-each>
<xsl:for-each select="*">
<tr>
<td><xsl:valu e-of select="name()" /></td>
<td><xsl:valu e-of select="." /></td>
</tr>
</xsl:for-each>
</xsl:template>
<xsl:template match="forms">
<xsl:for-each select="*">
<xsl:call-template name="label-value" />
</xsl:for-each>
</xsl:template>
Comment