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

Re: Iterating over values in a table of data

Subject: Re: Iterating over values in a table of data
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 07 Jun 2006 11:42:25 -0400
repeater item value
Hi,

Backwards from Andrew's answer:

<input>
    <!-- This is a table of lookup values. -->
    <data>
        <item>
            <value>one</value>
        </item>
        <item>
            <value>two</value>
        </item>
        <item>
            <value>three</value>
        </item>
    </data>
    <!-- This node needs to be repeatedly transformed for each input
data item -->
    <repeat>
            Item <value-of name="value"/> is in position <position-of
name="value"/>
    </repeat>
</input>

<xsl:stylesheet ...>


<xsl:variable name="repeater" select="/input/repeat"/>

<xsl:template match="repeat"/>
<!-- suppresses output on default traversal -->

<xsl:template match="data">
  <xsl:for-each select="item">
    <xsl:apply-templates select="$repeater" mode="repeat">
      <xsl:with-param name="item" select="."/>
      <xsl:with-param name="pos" select="position()"/>
    </xsl:apply-templates>
  </xsl:for-each>
</xsl:template>

<xsl:template match="repeat" mode="repeat">
  <xsl:param name="item" select="/.."/>
  <xsl:param name="pos" select="0"/>
  <item>
    <xsl:apply-templates>
      <xsl:with-param name="item" select="$item"/>
      <xsl:with-param name="pos" select="position()"/>
    </xsl:apply-templates/>
  </item>
</xsl:template>

<xsl:template match="value-of">
  <xsl:param name="item"/>
  <xsl:value-of select="$item"/>
</xsl:template>

<xsl:template match="position-of">
  <xsl:param name="pos"/>
  <xsl:value-of select="$pos"/>
</xsl:template>

</xsl:stylesheet>

Untested.

Cheers,
Wendell

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.