[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] how to get variable value outside scope


Subject: [xsl] how to get variable value outside scope
From: "Brian Phelps" <bphelps@xxxxxxxxxxx>
Date: Sat, 26 Feb 2005 15:35:25 -0800

I have an application whose data resides in an Access database. The
application bascially loops through a number of categories, and for each
item ("news_post") in each category, loops through and transforms the
data into HTML. What I am trying to do is capture the value of the
"category" variable and pass it outside the current scope so I can link
to another page with more content relevant to the specific category. 

I don't know how to either declare the variable in a scope that will
achieve my purpose, or pass the value through. 

http://iisstage.pacific.edu/homepage/events/pacific-event-calendar.asp

Above is a link to the output and here's the code below. Any help would
be appreciated.



<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ms="urn:schemas-microsoft-com:xslt">
	<xsl:output method="html"/>
	<xsl:template match="/">
		<div>
			<xsl:apply-templates/>
		</div>
	</xsl:template>
	<xsl:template match="news_posts">
		<!-- check for empty node - no posts found - give error
message if not -->
		<xsl:if test="not(node())">
			<tr>
				<xsl:text
disable-output-escaping="yes">&lt;td width="100%"
valign="top"&gt;</xsl:text>
   			No events are currently scheduled.
		 <xsl:text
disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
			</tr>
		</xsl:if>
		<!-- display posts if found -->
		<xsl:variable name="pagename">
			<xsl:value-of select="../page_info/@pagename"/>
		</xsl:variable>
		<xsl:variable name="single">
			<xsl:value-of
select="../page_info/@singlepost"/>
		</xsl:variable>
		<!-- output only first 2 posts -->
		<xsl:choose> 
		<xsl:if test="count(news_post) &lt; 3">
		<!-- end test count value -->
		<xsl:text>News post count 1A: </xsl:text>
		<xsl:value-of disable-output-escaping="yes"
select="count(news_post)"></xsl:value-of><br />
		<xsl:for-each select="news_post">
			<xsl:sort order="ascending" select="."/>
			<xsl:attribute
name="id"><xsl:text>zNews</xsl:text><xsl:value-of
select="position()"/></xsl:attribute>
			<tr>
				<xsl:text
disable-output-escaping="yes">&lt;td valign="top" width="33%"
class='zcontent'&gt;</xsl:text>
				<xsl:value-of select="short"
disable-output-escaping="yes" />
				<xsl:text
disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
				<xsl:text
disable-output-escaping="yes">&lt;td valign="top" width="66%"
class='zcontent'&gt;</xsl:text>
					<div class="zheadline">
					 <a class="zheadtitleUnderline">
						<xsl:attribute
name="href">
						
<xsl:text>mainevents.asp?postid=</xsl:text>
						 <xsl:value-of
select="@postid" />
						</xsl:attribute>
						 <xsl:value-of
select="title" disable-output-escaping="yes" />
					 </a>
					 </div>
				<xsl:text
disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
				<!-- check value -->
				<xsl:value-of select="news_post"
disable-output-escaping="yes"/>
				<xsl:text
disable-output-escaping="yes">&lt;/tr&gt;</xsl:text>
				<!-- print test count value -->
				
				
				
			<xsl:text
disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
		</tr>
			<!--</xsl:if>-->
		</xsl:for-each>
		<!-- end test for number of posts -->
		</xsl:if>
		<xsl:if test="$nPosts &gt; 1"> 
				 	<tr>
					<xsl:text
disable-output-escaping="yes">&lt;td colspan=2 valign ="top"
width="100%" class='zcontent'&gt;</xsl:text>
						 <div align="right">
						 <xsl:text
disable-output-escaping="yes">&lt;a href='pacific-</xsl:text>
						 <xsl:value-of
select="category" disable-output-escaping="yes" />
						 <!--<xsl:value-of
select="$nCategory" disable-output-escaping="yes" />-->
						 <xsl:text
disable-output-escaping="yes">-events.asp'&gt;more
&gt;&gt;&lt;/a&gt;</xsl:text>
						 </div>
					<xsl:text
disable-output-escaping="yes">&lt;/td&gt;</xsl:text>
					</tr>	 
				</xsl:if>
		

Brian Phelps

Web Manager
Marketing and University Relations
(209) 946-3273 PST

For current web site updates, stay informed:
http://www.pacific.edu/developers/

AIM/Yahoo IM: btphelps
icq: 221376

University of the Pacific
Stockton, CA
www.pacific.edu


Current Thread