|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
||||
|
||||
|
Logical Switch for Formatting XML to HTML Display
I need to loop through a set of elements and display only those based on certain criteria. This is no problem except that I can't figure out how to flip a switch that indicates wether it is the first /last time through to properly display the html formatting.
Ok here is a snippet of my xml: <!-- ============ Notes used =========== --> <notes> <note id="1" discipline="law"> <desc_long>#1 If the incident were Law Enforcement only, a seventh activity, a Staging Area, would be added. Also, if Law Enforcement only, each activity would have its own independent Chief/Officer.</desc_long> </note> <note id="2" discipline="law"> <desc_long>#2 If the incident were Law Enforcement only, a seventh activity, a Staging Area, would be added. Also, if Law Enforcement only, each activity would have its own independent Chief/Officer.</desc_long> </note> </notes> And here is a portion of my XSL: <!-- ============ XSL used =========== --> <xsl:template match="note"> <xsl:for-each select="../../notes/note"> <xsl:if test="(@discipline='all') or (@discipline=$discipline)"> <xsl:call-template name="notesource"/> </xsl:if> </xsl:for-each> </xsl:template> <xsl:template name="notesource"> <xsl:if test="$mblnFoundNote='False'"> <!-- ONLY WRITE THIS IF IT'S THE FIRST TIME THROUGH --> <xsl:with-param name="mblnFoundNote" select="'True'"/> <div class="content"> <h1>Notes: </h1> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td height="35"> <ol> </xsl:if> <xsl:if test="(@discipline='all') or (@discipline=$discipline)"> <span class="res"> <li> <xsl:value-of select="."/> </li> </span> </xsl:if> <xsl:if test="$mblnFoundNote='True'"> <!-- ONLY WRITE THIS IF IT'S THE LAST TIME THROUGH --> </ol> </td> </tr> </table> </div> </xsl:if> </xsl:template> |
|
#2
|
|||
|
|||
|
I think the best solution is to do the stuff you only want done once outside of the for-each loop in your note template. If you need to only output if there are notes, make a template that tries to match (@discipline='all') or (@discipline=$discipline) before and after the for-each loop.
|
|
#3
|
||||
|
||||
|
echolalia - yes but how do you do that with only portions of the html. I bellieve it fails the wellformdness check. to do the following:
Code:
<xsl:for-each select="/root/element"> <xsl:choose> <xsl:when test="position()=1"> <div class="content"> <h1>Notes: </h1> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td height="35"> <ol> <xsl:if test="(@discipline='all') or (@discipline=$discipline)"> <span class="res"> <li> <xsl:apply-templates select="desc_long"/> </li> </span> </xsl:if> </xsl:when> <xsl:when test="position()=last()"> <xsl:if test="(@discipline='all') or (@discipline=$discipline)"> <span class="res"> <li> <xsl:apply-templates select="desc_long"/> </li> </span> </xsl:if> </ol> </td> </tr> </table> </div> </xsl:when> <xsl:otherwise> <xsl:if test="(@discipline='all') or (@discipline=$discipline)"> <span class="res"> <li> <xsl:apply-templates select="desc_long"/> </li> </span> </xsl:if> </xsl:otherwise> </xsl:choose> <xsl:value-of select="."/> <br/> </xsl:for-each> Last edited by mrusaw : July 8th, 2003 at 02:26 PM. |
|
#4
|
||||
|
||||
|
I added what i could. I hope it gives you enough to see what I am attempting. I also put a screen shot of where it goes and what i was expecting. Let me know if that makes sense.
|
|
#5
|
||||
|
||||
|
woops here is the attachment
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Logical Switch for Formatting XML to HTML Display |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|