RE: [TFUI] OT? "if" in XSLT (Re: XML -> XSLT -> XHTML Nirvana)
"Bayley, Alistair" <[email protected]> Mon, 14 Mar 2005 13:24:02 -0000
| Newsgroups | gmane.comp.programming.test-first-user-interfaces |
|---|---|
| Message-ID | <7DFF3BC6CA957441AEADA7F340BFAA340A0293D9@GBLONEX11.lon.invesco.com> |
<HTML> <BODY> > From: Ron Jeffries [mailto:[email protected]] > > 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: I took your XML and tested it with some sample input, to see what it would produce: -- input: <header> <title>title-text</title> <shorttitle>shorttitle-text</shorttitle> <file>file1.txt</file> </header> -- output (formatted for Yahoo-groups): <?xml version="1.0" encoding="UTF-16"?> <span class="indextitle" xmlns:msxsl="urn:schemas-microsoft-com:xslt" /> <span class="indextitle" xmlns:msxsl="urn:schemas-microsoft-com:xslt"> <a href="root/xpmag/file1.txt">shorttitle-text</a> </span> file1.txt Ignoring the "file1.txt" crud at the end (I'm not sure why this is happening; my XSLT-fu is mediocre), you can see that both templates produce output. The title template produces an empty <span>, because the test is inside the <span>. I assume that this is not what you intended, although harmless. Do you think maybe this would be a better way? <xsl:template match="header/title"> <span class="indextitle"> <a> <xsl:attribute name="href"> <xsl:value-of select="$root"/>xpmag/<xsl:value-of select="../file"/> </xsl:attribute> <xsl:choose> <xsl:when test="not(../shorttitle)"><xsl:value-of select="../title"/></xsl:when> <xsl:otherwise><xsl:value-of select="../shorttitle"/></xsl:otherwise> </xsl:choose> </a> </span> </xsl:template> It produces the link correctly, but there's still extra crud in the output, just like the "file1.txt" line in the first test. Alistair. <P><hr size=1></P> <P><STRONG> *****************************************************************<br>Confid entiality Note: The information contained in this <br>message, and any attachments, may contain confidential <br>and/or privileged material. It is intended solely for the <br>person(s) or entity to which it is addressed. Any review, <br>retransmission, dissemination, or taking of any action in <br>reliance upon this information by persons or entities other <br>than the intended recipient(s) is prohibited. If you received<br>this in error, please contact the sender and delete the <br>material from any computer.<br >***************************************************************** </STRONG></P> </BODY> </HTML> 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/