xsl-list
[Top] [All Lists]

RE: [xsl] round-robin template call

2009-04-05 13:39:32
Hello,

I'm not sure I understand your requirements, but the context
is available to named templates, so you may use information
from the source file at the point where the named template
is called, as an input for a test in the named template.

For example, this XSLT:

<xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:template match="/">
        <root>
                <xsl:apply-templates/>
                </root>
        </xsl:template>
<xsl:template match="*">
        <element name="{name()}">
                <xsl:call-template name="test"/>
                <xsl:apply-templates/>
                </element>
        </xsl:template>
<xsl:template name="test">
        <xsl:choose>
                <!-- is there an element named 'a' as a direct child of the 
context node? -->
                <xsl:when test="a">
                        <case no="1"/>
                        </xsl:when>
                <xsl:when test="b">
                        <case no="2"/>
                        </xsl:when>
                <xsl:otherwise>
                        <case no="other"/>
                        </xsl:otherwise>
                </xsl:choose>
        </xsl:template>
</xsl:stylesheet>

applied to this source document:

<root>
        <a>
                <b>
                        <c>
                                <a/>
                                </c>
                        </b>
                </a>
        </root>

outputs this:

<root>
   <element name="root">
      <case no="1"/>
      <element name="a">
         <case no="2"/>
         <element name="b">
            <case no="other"/>
            <element name="c">
               <case no="1"/>
               <element name="a">
                  <case no="other"/>
               </element>
            </element>
         </element>
      </element>
   </element>
</root>

Also see this for example:
www.zvon.org/xxl/XSL-Ref/Tutorials/Named-Templates/nt2.html

HTH

Regards,
EB

-----Original Message-----
From: Aragon Gouveia [mailto:aragon(_at_)phat(_dot_)za(_dot_)net]
Sent: Sunday, April 05, 2009 7:10 PM

I want to avoid passing parameters during the template call.




--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>