xsl-list
[Top] [All Lists]

Re: [xsl] Using for-each on user arguments [was: Re: Passing a list of arguments]

2007-11-09 07:21:49
Mathieu Malaterre wrote:

  Hi

  <xsl:variable name="sections-list">
    <args>
      <arg>C.8.7.1.1.2</arg>
      <arg>C.8.14.1.1</arg>
    </args>
  </xsl:variable>

  <xsl:template match="article">
    <xsl:param name="extract-section"/>
    <el>
      <xsl:value-of select="$extract-section"/>
    </el>
  </xsl:template>

  <xsl:template match="/">
    <e>
      <xsl:for-each select="$sections-list/args/arg">
        <xsl:apply-templates select="article">
          <xsl:with-param name="extract-section" select="."/>
        </xsl:apply-templates>
      </xsl:for-each>
    </e>
  </xsl:template>
</xsl:stylesheet>

  The context changes within the for-each.  You can either keep a
reference to the nodes you want to apply templates to, or instead use
the variable in the template rule, depending on what is semantically
better:

    <!--
        If you want a list of strings, use a list of strings.
    -->
    <xsl:variable name="sections-list" as="xs:string+" select="
        'C.8.7.1.1.2', 'C.8.14.1.1'"/>

    <xsl:template match="article">
       <xsl:param name="extract-section" as="xs:string"/>
       <el>
          <xsl:value-of select="$extract-section"/>
       </el>
    </xsl:template>

    <xsl:template match="/">
       <e>
          <xsl:variable name="a" as="element()+" select="article"/>
          <xsl:for-each select="$sections-list">
             <xsl:apply-templates select="$a">
                <xsl:with-param name="extract-section" select="."/>
             </xsl:apply-templates>
          </xsl:for-each>
       </e>
    </xsl:template>

or:

    <xsl:template match="article">
       <xsl:for-each select="$sections-list">
          <el>
             <xsl:value-of select="."/>
          </el>
       </xsl:for-each>
    </xsl:template>

    <xsl:template match="/">
       <e>
          <xsl:apply-templates select="article"/>
       </e>
    </xsl:template>

  Regards,

--drkm


























      
_____________________________________________________________________________ 
Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail 


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--