Microsoft HomeproductssearchsupportshopWrite Us   Microsoft Home
Magazine
 |  Community
 |  Workshop
 |  Tools & Samples
 |  Training
 |  Site Info

Workshop  |  XML (Extensible Markup Language)

xsl:for-each Element


Allows application of the same template to multiple nodes.

Syntax

<xsl:for-each
    order-by="{+|-} xsl-pattern" 
    select="pattern" >

Attributes

order-by
First character selects the sort direction, either ascending (+) or descending (-). The rest of the pattern is a limited version of the XSL Pattern-Matching Syntax.
select
XSL pattern to be matched against the current context. The default value "node()" indicates evaluation of the current node.

Element Information

Number of occurrences Unlimited
Parent elements xsl:attribute, xsl:cdata, xsl:comment, xsl:copy, xsl:element, xsl:for-each, xsl:if, xsl:otherwise, xsl:pi, xsl:template, xsl:text, xsl:when
Child elements xsl:apply-templates, xsl:attribute, xsl:choose, xsl:cdata, xsl:comment, xsl:copy, xsl:define-template-set, xsl:element, xsl:entity-ref, xsl:eval, xsl:for-each, xsl:if, xsl:node-name, xsl:pi, xsl:value-of
Requires closing tag Yes. XSL is an XML grammar and, like all XML grammars, all tags must have closing tags to satisfy the definition of well-formed.

Remarks

The xsl:for-each element establishes the context for iteration; the XSL transformation instructions within this loop are to be applied to each node that matches the supplied pattern. Each xsl:for-each element defines a new context against which the pattern-matching occurs.

Example

This example specifies a template that defines what the structure of the overall output document should be (a top-level HTML element containing BODY and TABLE elements with repeated rows for each customer) and uses templates to create TD elements for the name, address, and phone source elements.


<HTML xmlns:xsl="http://www.w3.org/TR/WD-xsl">
  <BODY>
    <TABLE>
      <xsl:for-each select="customers/customer">
        <TR>
          <xsl:value-of select="name" />
          <xsl:value-of select="address" />
          <xsl:value-of select="phone" />
        </TR>
      </xsl:for-each>
    </TABLE>
  </BODY>
</HTML>

See Also

XSL Elements


Does this content meet your programming needs? Write us!

Back to topBack to top

© 1998 Microsoft Corporation. All rights reserved. Terms of use.

 

Magazine Home
Ask Jane
DHTML Dude
Extreme XML
For Starters
More or Hess
Servin' It Up
Site Lights
Web Men Talking
Member Community Home
Benefits: Freebies & Discounts
Benefits: Promote Your Site
Benefits: Connect with Your Peers
Benefits at a Glance
Online Special-Interest Groups
Your Membership
SBN Stores
Join Now
Workshop Home
Essentials
Content & Component Delivery
Component Development
Data Access & Databases
Design
DHTML, HTML & CSS
Extensible Markup Language (XML)
Languages & Development Tools
Messaging & Collaboration
Networking, Protocols & Data Formats
Reusing Browser Technology
Security & Cryptography
Server Technologies
Streaming & Interactive Media
Web Content Management
Workshop Index
Tools & Samples Home
Tools
Samples, Headers, Libs
Images
Sounds
Style Sheets
Web Fonts
Training Home
SBN Live Seminars
SBN Live Chats
Courses
Peer Support
CD-ROM Training
Books & Training Kits
Certification
SBN Home
New to SBN?
What's New on SBN
Site Map
Site Search
Glossary
Write Us
About This Site