Subject: RE: how to get variable value outside scope
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sun, 27 Feb 2005 03:25:20 -0000
|
As DC says, the first thing you need to do with this stylesheet is to get
rid of the d-o-e: using d-o-e is fighting against the language rather than
going with the grain.
It would also be a good idea to sort out these constructs:
<xsl:variable name="pagename">
<xsl:value-of select="../page_info/@pagename"/>
</xsl:variable>
This should almost always be simplified to:
<xsl:variable name="pagename" select="../page_info/@pagename"/>
(This isn't just cosmetic: you are creating lots of copies of data where you
only need a reference to the original data).
Your stylesheet contains
<xsl:choose>
<xsl:if test="count(news_post) < 3">
which the compiler should have thrown out: the only things allowed inside
xsl:choose are xsl:when and xsl:otherwise.
As for the substance of your question, I'm sorry, but I can't see the
relationship between the code you presented and the question you asked.
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: Brian Phelps [mailto:bphelps@xxxxxxxxxxx]
> Sent: 26 February 2005 23:35
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: how to get variable value outside scope
>
> 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"><td width="100%"
> valign="top"></xsl:text>
> No events are currently scheduled.
> <xsl:text
> disable-output-escaping="yes"></td></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) < 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"><td valign="top" width="33%"
> class='zcontent'></xsl:text>
> <xsl:value-of select="short"
> disable-output-escaping="yes" />
> <xsl:text
> disable-output-escaping="yes"></td></xsl:text>
> <xsl:text
> disable-output-escaping="yes"><td valign="top" width="66%"
> class='zcontent'></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"></td></xsl:text>
> <!-- check value -->
> <xsl:value-of select="news_post"
> disable-output-escaping="yes"/>
> <xsl:text
> disable-output-escaping="yes"></tr></xsl:text>
> <!-- print test count value -->
>
>
>
> <xsl:text
> disable-output-escaping="yes"></td></xsl:text>
> </tr>
> <!--</xsl:if>-->
> </xsl:for-each>
> <!-- end test for number of posts -->
> </xsl:if>
> <xsl:if test="$nPosts > 1">
> <tr>
> <xsl:text
> disable-output-escaping="yes"><td colspan=2 valign ="top"
> width="100%" class='zcontent'></xsl:text>
> <div align="right">
> <xsl:text
> disable-output-escaping="yes"><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'>more
> >></a></xsl:text>
> </div>
> <xsl:text
> disable-output-escaping="yes"></td></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
|