Subject: Re: [xsl] mixed content nodes question From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Fri, 07 Jan 2005 15:56:36 -0500 |
On Jan 7, 2005, at 2:17 PM, Antsnio Mota wrote:
Or to one who doesn't like if's
<xsl:template match="dictionary[lookup = '3']>Foo<xsl:/template> <xsl:template match="dictionary[lookup = '4']>Foo<xsl:/template>
You have to change your mind from the "for...loop" paradigm to the template paradigm, that's not easy at first but when you do all things came in place...
I finally started realizing this yesterday and was like, "oh...it's kinda supposed to be like a crazy-syntaxed version of Scheme..."
They decided to do it this way because XSLT's very powerful predecessor, DSSSL, used Scheme syntax, but apparently people didn't like it.
(element cited.title (let ((rendition (attribute-string "render"))) (case rendition (("bold") ($bold-seq$)) (("quoted") ($quoted-seq$)) (else ($italic-seq$)))))
(define ($italic-seq$ #!optional (children (process-children))) (make element gi: "i" children))
<xsl:template match="cited.title"> <xsl:choose> <xsl:when test="@render = 'bold'"> <xsl:call-template name="bold-seq"/> </xsl:when> <xsl:when test="@render = 'quoted'"> <xsl:call-template name="quoted-seq"/> </xsl:when> <xsl:otherwise> <xsl:call-template name="italic-seq"/> </xsl:otherwise> </xsl:choose> </xsl:template>
<xsl:template name="italic-seq"> <xsl:param name="children"> <xsl:apply-templates/> </xsl:param> <i> <xsl:copy-of select="$children"/> </i> </xsl:template>
Notice in the DSSSL version the value of @render in the first element construction rule (sc. "template") is bound to a variable. I suppose this is because the author didn't want to continue calling the "attribute-string" procedure over and over. (DSSSL didn't have axes in the sense XSLT does.) Also notice how the "italic-seq" procedure is designed so it can wrap anything in italics, but continues traversing the tree ("process-children" being DSSSL's version of <xsl:apply-templates/>) by default. This is also a handy technique in XSLT sometimes.
Cheers, Wendell
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] mixed content nodes quest, Jeb Boniakowski | Thread | Re: [xsl] mixed content nodes quest, António Mota |
RE: [xsl] mixed content nodes quest, Mark Lundquist | Date | [xsl] lookup table (was: mixed cont, Kevin Rodgers |
Month |