[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: mixed content nodes question

Subject: Re: mixed content nodes question
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 07 Jan 2005 15:56:36 -0500
xslt mixed content
At 02:22 PM 1/7/2005, Jeb wrote:
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..."

That's exactly what it is. Well, exactly, more or less sort of.


They decided to do it this way because XSLT's very powerful predecessor,
DSSSL, used Scheme syntax, but apparently people didn't like it.

For historical interest, here's a bit of DSSSL:

(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))

In XSLT this would be

<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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.