[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] XSLT Generators / xsl:for-each vs. xsl:template


Subject: [xsl] XSLT Generators / xsl:for-each vs. xsl:template
From: "Kyle D. Morton" <kyle_morton@xxxxxxxxxxx>
Date: Wed, 9 May 2001 18:48:35 -0400

I have developed an XSLT Generating Java API that works by creating
"mapping" statements with XPath. It works in a similar way to existing
commercial IDE products but lets a developer embed the functioanlity into
their own software. Perhaps the main differentiator of this API is that it
does not require a source or target DTD/Schema to begin; it is entirely
XPath driven.

The XSLT code it generates is different from other available products like
XSLWiz, Stylus, etc.. The XSLT generated by those products relies on
xsl:for-each loops to select the appropriate elements. In my API I don't use
loops, but recursion with xsl:template elements.

My question is if there are any strong feelings out there in regard to the
loop vs. recursion model of writing XSLT.

For Example:

this
<xsl:template match="/">
 <News>
  <xsl:apply-templates select="rss/channel/item"/>
 </News>
</xsl:template>
<xsl:template match="rss/channel/item">
 <Article>
  <xsl:apply-templates select="title"/>
 </Article>
</xsl:template>
<xsl:template match="title">
 <Headline>
  <xsl:value-of select="text()"/>
 </Headline>
</xsl:template>

vs.

<xsl:template match="/">
 <News>
  <xsl:for-each select="rss/channel/item">
  <Article>
   <Headline><xsl:value-of select="title"/></Headline>
  </Article>
  </xsl:for-each>
 </News>
</xsl:template>

My feeling is that using xsl:template will allow for more complex
transformation by using the "mode" attribute to group rules. But I would
like any opinions.

Thanks in advance.
-Kyle Morton

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords