Re: [TFUI] OT? "if" in XSLT (Re: XML -> XSLT -> XHTML Nirvana)
Ron Jeffries <[email protected]>
| Newsgroups | gmane.comp.programming.test-first-user-interfaces |
|---|---|
| Organization | XProgramming.com |
| Message-ID | <[email protected]> |
On Sunday, March 13, 2005, at 1:57:31 PM, J. B. Rainsberger wrote:
> More to the point, why should one need "if" at all? If "if" should
> happen when generating the XML, and the corresponding template is either
> applied or not applied. There is no "if".
In my site generation XSLT, an article has two titles. One, <title>
is used most of the time. But if a title named <shorttitle> exists,
that title is to be used in the index pages. Basically it's
necessary to /decide/ whether title should be applied, based on
whether shorttitle is there. The code looks like this, basically
suppressing title in favor of shorttitle:
<xsl:template match="header/title">
<span class="indextitle">
<xsl:if test="not(../shorttitle)">
<a>
<xsl:attribute name="href">
<xsl:value-of select="$root"/>xpmag/<xsl:value-of select="../file"/>
</xsl:attribute>
<xsl:apply-templates/>
</a>
</xsl:if>
</span>
</xsl:template>
<xsl:template match="header/shorttitle">
<span class="indextitle">
<a>
<xsl:attribute name="href">
<xsl:value-of select="$root"/>xpmag/<xsl:value-of select="../file"/>
</xsl:attribute>
<xsl:apply-templates/>
</a>
</span>
</xsl:template>
There may be a better way, but at the time I couldn't think of it,
and right now I don't see one offhand.
Ron Jeffries
www.XProgramming.com
He who will not apply new remedies must expect old evils. -- Francis Bacon
To unsubscribe, email:
TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/TestFirstUserInterfaces/
<*> To unsubscribe from this group, send an email to:
TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/