Hello, I'm trying to use XSL to the fullest by using templates instead of repeating my code. I have "PART" nodes that can be in the root document itself, or can be embedded in one or many levels deep in an "OPTION_CLASS" tag. Anytime I find at least one child PART node, I need to create a table and a form, and then loop through all of the parts on the same level, to create the table lines. I think I'm pretty close, I just need to properly select the PART siblings.
XML:
Main Template:
Part Form Template:
Part Line Template:
So how can I print the table and form if I see at least 1 PART node, and then loop through all the parts on that level?
Thanks,
Mike
XML:
Code:
<PACKAGE id = "1">
<OPTION_CLASS id = "2">
<OPTION_CLASS id = "3">
<PART id = "4"/>
<PART id = "4"/>
<PART id = "4"/>
<OPTION_CLASS id = "5">
<PART id = "6"/>
<PART id = "6"/>
</OPTION_CLASS>
</OPTION_CLASS>
<PART id = "7"/>
<PART id = "7"/>
<PART id = "7"/>
</OPTION_CLASS>
<OPTION_CLASS id = "8">
<PART id = "9"/>
<PART id = "9"/>
</OPTION_CLASS>
<PART id = "10"/>
<PART id = "11"/>
</PACKAGE>
Main Template:
Code:
<xsl:template match = "/*">
<!--### I don't know if [position()=1] is correct, but it would repeat the form otherwise ###-->
<xsl:apply-templates select="PART[position()=1]" mode="form"/>
<xsl:apply-templates select="/BUNDLE/OPTION_CLASS"/>
</xsl:template>
Part Form Template:
Code:
<xsl:template match="PART" mode="form">
<p/>
<form action = "part" method = "get">
<input type = "hidden" name = "p_action" value = "UPDATE_LINE"/>
<table cellpadding = "3" bgcolor = "#F5F5FF">
<tr>
<th>Part Number</th>
<th>Sequence</th>
<th>Optional</th>
<th>Pre-Selected</th>
</tr>
<!--###HERE IS WHERE I NEED TO SELECT ALL PART SIBLINGS###-->
<xsl:apply-templates select="./PART" mode="line"/>
<tr>
<td colspan = "4"><input type = "submit" value = "Update Parts"/></td>
</tr>
</table>
</form>
</xsl:template>
Part Line Template:
Code:
<xsl:template match="PART" mode="line">
<input type = "hidden" name = "p_header_id">
<xsl:attribute name = "value">
<xsl:value-of select = "@header_id"/>
</xsl:attribute>
</input>
<input type = "hidden" name = "p_line_id">
<xsl:attribute name = "value">
<xsl:value-of select = "@line_id"/>
</xsl:attribute>
</input>
<tr>
<td><xsl:value-of select = "@part_number"/></td>
<td>
<input type = "text" name = "p_sequence" size = "3" autocomplete = "OFF">
<xsl:attribute name = "value">
<xsl:value-of select = "@sequence"/>
</xsl:attribute>
</input>
</td>
<td>
<select name = "p_optional">
<xsl:if test = "@optional = 'Y'">
<option value="Y" selected="true">Yes</option>
<option value="N">No</option>
</xsl:if>
<xsl:if test="@optional != 'Y'">
<option value="Y">Yes</option>
<option value="N" selected="true">No</option>
</xsl:if>
</select>
</td>
<td>
<select name = "p_default_flag">
<xsl:if test = "@default_flag = 'Y'">
<option value="Y" selected="true">Yes</option>
<option value="N">No</option>
</xsl:if>
<xsl:if test="@default_flag != 'Y'">
<option value="Y">Yes</option>
<option value="N" selected="true">No</option>
</xsl:if>
</select>
</td>
</tr>
</xsl:template>
So how can I print the table and form if I see at least 1 PART node, and then loop through all the parts on that level?
Thanks,
Mike