XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old July 8th, 2003, 09:12 AM
mrusaw's Avatar
mrusaw mrusaw is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Dallas, Texas
Posts: 138 mrusaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to mrusaw Send a message via Yahoo to mrusaw
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>

Reply With Quote
  #2  
Old July 8th, 2003, 12:31 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
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.

Reply With Quote
  #3  
Old July 8th, 2003, 02:15 PM
mrusaw's Avatar
mrusaw mrusaw is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Dallas, Texas
Posts: 138 mrusaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to mrusaw Send a message via Yahoo to mrusaw
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.

Reply With Quote
  #4  
Old July 8th, 2003, 03:50 PM
mrusaw's Avatar
mrusaw mrusaw is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Dallas, Texas
Posts: 138 mrusaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to mrusaw Send a message via Yahoo to mrusaw
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.

Reply With Quote
  #5  
Old July 8th, 2003, 03:51 PM
mrusaw's Avatar
mrusaw mrusaw is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Dallas, Texas
Posts: 138 mrusaw User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to mrusaw Send a message via Yahoo to mrusaw
woops here is the attachment
Attached Files
File Type: zip xsl.zip (308.6 KB, 237 views)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Logical Switch for Formatting XML to HTML Display


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway