EXSLT - func:function - Use Case 2

Category: example
XML Definition: func.function.xml

This use case tests a function definition that uses local variables.

Use Case

Source (view)

<doc>
   <section index="section1"
            index2="atr2val">
      <section index="subSection1.1">
         <p>Hello</p>
         <p>Hello again.</p>
      </section>
   </section>
   <section index="section2">
      <p>Hello2</p>
      <section index="subSection2.1">
         <p>Hello</p>
         <p>Hello again.</p>
      </section>
      <section index="subSection2.2">
         <p>Hello</p>
         <p>Hello again.</p>
      </section>
      <p>Hello2 again.</p>
      <section index="subSection2.3">
         <p>Hello</p>
         <p>Hello again.</p>
      </section>
   </section>
</doc>

Stylesheet (view)

<!--  Test an EXSLT function with local variables  -->
<func:function name="func:count-elements-and-attributes">
   <xsl:variable name="elements"
                 select="//*" />
   <xsl:variable name="attributes"
                 select="//@*" />
   <func:result select="count($elements | $attributes)" />
</func:function>
<xsl:template match="/">
   <out>
      <el>
         <xsl:value-of select="count(//*)" />
      </el>
;
          <at>
         <xsl:value-of select="count(//@*)" />
      </at>
;
            <xsl:value-of select="func:count-elements-and-attributes()" />
   </out>
</xsl:template>

Result (view)

<out>
   <el>17</el>
;
       <at>7</at>
;
      24
</out>

Change History

Previous Version: ..NaN.html

VersionModifiedByDetails
12001-04-28Mike Kay

Tests functionality of func:function.

http://www.exslt.org/func/elements/function/func.function.use-case.2.html last modified 2001-04-28