xsl-list
[Top] [All Lists]

Re: Re: [xsl] dynamic template caller problems

2006-07-30 13:32:37
Thanks for your replies.

Based upon the idea from 
http://archive.gingerall.cz/archives/public/sablot2002/msg00925.html, I wrote 
the following:


XML-file:
===============================================

<?xml version='1.0' encoding='utf-8'?>
<root>
    <page1 template="single" />
    <page2 template="double" />
    <page3 template="single" />
    <page4 template="float" />
    <page5 template="double" />
    <page6 template="double" />
</root>


XSL-File:
===============================================

...
<xsl:template match="/">
                
        <!-- simplifies REQUEST_URI: "/a(/)" -> "a" -->
        <xsl:variable name="REQUEST_URI" select="translate($REQUEST_URI,'/ 
','')" />
        
        <!--<xsl:copy&#45;of select="$REQUEST_URI" />-->
        <!-- get "template" -->
        <xsl:variable name="template" 
select="dyn:evaluate(concat('/root/',$REQUEST_URI,'/@template'))" />
                
        <!--<xsl:copy&#45;of select="$template" />-->
        <!-- apply related template -->
        <xsl:apply-templates select="dyn:evaluate(concat('//',$REQUEST_URI))" />
</xsl:template>
        
<xsl:template match="*[(_at_)template='single']">
        <p>single template selected</p>
</xsl:template>
    
<xsl:template match="*[(_at_)template='float']">
        <p>float template selected</p>
</xsl:template>
    
<xsl:template match="*[(_at_)template='double']">
        <p>double template selected</p>
</xsl:template>
...


I haven't tried yet, to access the node related to the selected template from 
inside (=from inside of the selected template), but I'm confident of this.


Cheers, S.R.

-------- Original-Nachricht --------
Datum: Sun, 30 Jul 2006 21:23:11 +0100
Von: David Carlisle <davidc(_at_)nag(_dot_)co(_dot_)uk>
An: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Betreff: Re: [xsl] dynamic template caller problems



just use
<xsl:apply-templates/>

and have (eg)
<xsl:template match="page2[(_at_)template='template_b']">

no need to make it difficult by using template names here.

David

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

-- 


Echte DSL-Flatrate dauerhaft für 0,- Euro*. Nur noch kurze Zeit!
"Feel free" mit GMX DSL: http://www.gmx.net/de/go/dsl

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