Re: [TFUI] "if" in XSLT (Re: XML -> XSLT -> XHTML Nirvana)

Phlip <[email protected]> Mon, 14 Mar 2005 06:57:48 -0800
Newsgroups gmane.comp.programming.test-first-user-interfaces
Message-ID <[email protected]>
Cory Foy wrote:

> 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".

J. B. might be making an oblique reference to a movie that I highly
anticipated avoiding.

> Ron's post brings up one scenario I can think of, but I have definitely
> encountered other times when xsl:if has come in handy. In my reply to
> Phlip, I mentioned that thing that was troubling me wasn't so much that
> there was conditional logic in the outputting code, but that the code
> was outputting presentation elements instead of pure data.
> 
> I would much rather see out of our code:
> 
> <title><highlight color="hotpink">The title</highlight></title>
> 
> then
> 
> <title><span style="background-color:hotpink">The title</span></title>

The question regards the /WebXP/ book's Prime Directive. The 'if'
statement exists because some titles are hot pink and some are not.

If you put the 'if' into the "real programming language" part of the
GUI Layer, then you must transmit XML into the XSLT and thence into
the XHTML, to follow the Prime Directive.

You could transmit it as a style attribute, and pass this into the
XHTML style attribute:

<title><span style="{@title_style}"><xsl:value-of
select="@title"></span></title>

(For those trying to catch up on the XSLT Prime Directive, that line
is XSLT reading XML to produce XHTML...)

Or, I can put the entire title span, as preformatted XHTML, into the XML:

set($thing, 'title', '<span style="background-color:hotpink">The title</span>');

Then the XSLT pushes that in, unescaped:

<title><xsl:value-of disable-output-escaping="yes" select="@title"></title>

I chose the latter, in a specific situation, for an unreviewed,
temporary, in-house web site. I chose the simplest way to get a lot of
flexibility. One cost is I must reformat the title itself as XHTML
(replacing & with &amp;, for example), before passing it into the XML.

When passing entire XHTML strings thru the XML as payload, I can push
in any markup code I like. For example, imagine a loop, <xsl:for-each
select="@*"> that loops thru attributes in the XML node, and prints
each ones name and value into a table. Most attribute values are
simple text, but one of them is a clickable image and a sub-table.

> (outside the whole hotpink thing)
> 
> The reason is that we often have to create data structures that are in
> turn processed for both web, mobile and pocket PC devices, and rather
> than have to modify the outputting code, I would rather modify the
> stylesheet.
> 
> Actually, thinking about it more, I would rather see
> 
> <title highlight="hotpink">The title</title>
> 
> That way XSLT sheets can determine if they want to use it or not, but
> the other sheets don't ever have to be aware of it. Using the highlight
> color as an attribute of the title means that we only have to have the
> xsl:if statement on those sheets that actually care about it.

Without the need to target more than one XSLT, I just partitioned the
flexibilities into the kinds of languages that make them easier.

However, are you implying that the "real programming language" side is
completely unaware whether the result appears on the web or in a cell
phone? Otherwise, aren't you also partitioning your flexibilities,
along different trade-offs?

-- 
Phlip


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/