View Single Post
  #1 (permalink)  
Old February 27th, 2006, 05:17 PM
xaun xaun is offline
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default preceding-sibling descendant

I am trying to put a list of class names in a table sometimes there needs to be 3 columns but most of the time there needs to be 4. If the Arg element in the XML is empty then there needs to be a </td></tr><tr> to close the sell and row and start another row. The below XSLT is not giving the desired result. This particular example is should be in 3 columns but the same XLST needs to be applicable for 3 and 4 columns.

Thanks in advance.

<xsl:template match="Group" >
    <table width="525">
        <tr>
            <td width="540" colspan="6"><xsl:value-of select="Header"/></td>
        </tr>
        <xsl:text disable-output-escaping="yes">
                &lt;tr&gt;
        </xsl:text>

        <xsl:for-each select="List/Course">

            <xsl:text disable-output-escaping="yes">
                &lt;td width="75" &gt;
            </xsl:text>
            <a href="javascript:poptastic('/myDegreePlanner/WebContent/jsps/coursedescription.jsp?course={Name}');"><xsl:value-of select="concat(Name,' ')"/> </a>
            <xsl:text disable-output-escaping="yes">
                &lt;/td&gt;
                &lt;td width="50" align="left" &gt;
            </xsl:text>
            <xsl:choose>
                <xsl:when test="Status = '(X)'">
                    <input name="" type="checkbox" disabled="true" value="" checked="checked" ></input>
                </xsl:when>
                <xsl:otherwise>
                    <input name="" type="checkbox" value="" />
                </xsl:otherwise>
            </xsl:choose>
            <xsl:value-of select="concat(Arg,' ')"/>
            <xsl:text disable-output-escaping="yes">
                    &lt;/td&gt;

            </xsl:text>

            <xsl:choose>
                <xsl:when test="Arg=''" >
                    <xsl:text disable-output-escaping="yes">
                        &lt;/tr&gt;&lt;tr&gt;

                    </xsl:text>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:choose>
                    <xsl:when test="position() mod 4 = 0" >
                        <xsl:if test="preceding-sibling::*[1][descendant::Arg] !=''">
                            <xsl:text disable-output-escaping="yes">
                                    &lt;/tr&gt;&lt;tr&gt;
                            </xsl:text>
                        </xsl:if>

                    </xsl:when>
                    <xsl:otherwise>
                            <xsl:if test="preceding-sibling::*[1][descendant::Arg] =''">

                            </xsl:if>

                    </xsl:otherwise>
                     </xsl:choose>
                </xsl:otherwise>
            </xsl:choose>

        </xsl:for-each>
        <xsl:text disable-output-escaping="yes">
            &lt;/tr&gt;
        </xsl:text>


    </table>
</xsl:template>

The XML looks like
<List>
                    <Course>
                        <Name>ORI2000</Name>
                        <Status>( )</Status>
                        <Arg>or</Arg>
                    </Course>
                    <Course>
                        <Name>SPC2016</Name>
                        <Status>( )</Status>
                        <Arg>or</Arg>
                    </Course>
                    <Course>
                        <Name>SPC2040</Name>
                        <Status>( )</Status>
                        <Arg/>
                    </Course>
                    <Course>
                        <Name>SPC2600</Name>
                        <Status>( )</Status>
                        <Arg>or</Arg>
                    </Course>
                    <Course>
                        <Name>MAC1102</Name>
                        <Status>( )</Status>
                        <Arg>or</Arg>
                    </Course>
                    <Course>
                        <Name>MAC1105</Name>
                        <Status>( )</Status>
                        <Arg/>
                    </Course>
                    <Course>
                        <Name>MAC1140</Name>
                        <Status>( )</Status>
                        <Arg>or</Arg>
                    </Course>
                    <Course>
                        <Name>MAC1114</Name>
                        <Status>( )</Status>
                        <Arg>or</Arg>
                    </Course>
                    <Course>
                        <Name>MAC1147</Name>
                        <Status>( )</Status>
                        <Arg/>
                    </Course>
                    <Course>
                        <Name>MAC2233</Name>
                        <Status>( )</Status>
                        <Arg>or</Arg>
                    </Course>
The results look like
ORI2000 or SPC2016 or SPC2040
SPC2600 or
MAC1102 or MAC1105
MAC1140 or MAC1114 or
MAC1147

Reply With Quote