Re: [xsl] for-each question

Subject: Re: [xsl] for-each question
From: Mike Brown <mike@xxxxxxxx>
Date: Tue, 13 Aug 2002 11:04:06 -0600 (MDT)
Vasu Chakkera wrote:
> The problem is your template matches each book element.
> this is equivalent to a pseudo code
> for each book {
> The books are:
> Book-Name
> }

No it is not. "for each" is an instruction, an operation.
A template is a declaration, a definition.

A lot of XSLT newbies tend to be under the mistaken impression that
xsl:template causes something to happen. Your pseudocode reinforces this
confusion. They need to be told that it is actually the xsl:apply-templates
that causes nodes to be selected and processed.

I would tell him that his template was equivalent to defining
the following functions (Python style):

def handleAnyNode(node,result):                       # xsl:template
  if node.type == ELEMENT and == 'book':    # match="book"
def handleBookNode(node,result):
    frag = ResultTreeFragment()
    frag.append(TextNode('The Books Are:'))           # The Books Are:
    frag.child[0].append(Element('I'))                # <I>...</I>
    frag.child[1].append(TextNode(currentNodeName())) # xsl:value-of

And that it was his <xsl:apply-templates select="book"> that was equivalent to

for node in getAllNodesMatchingXpathExpression('child::book'):

   - Mike
  mike j. brown                   |  xml/xslt:
  denver/boulder, colorado, usa   |  resume:

 XSL-List info and archive:

Current Thread