Re: [xsl] Java XSLT transformers and document('') problem

Subject: Re: [xsl] Java XSLT transformers and document('') problem
From: LS <leonid@xxxxxxxxxxxxx>
Date: Mon, 08 Sep 2008 15:31:41 +0600
but the behaviour is very different to that of call-template, any xsl
instructions in the matched template will be treated as data rather than
executed.

In the example that you gave there were no xsl instructions inside the
template so you could just use a variable and don't need a template at
all. Does your actual use case have xsl instructions inside the
template, perhaps the example you posted was over-simplified?
Of course, this was very simplified example.
I do this i.e. when generate web forms, based on input xml:

XML:
<document>
<name value="lala" mode="string"/>
<password value="dede" mode="password" />
</document>

XSL:
   <xsl:variable name="doc" select="/"/>

<xsl:template name="field_type_string" match="xsl:template[@name='field_type_string']">
<xsl:param name="i"/>
<tr>
<xsl:call-template name="controlset_caption">
<xsl:with-param name="i" select="$i"/>
</xsl:call-template>
<td class="inp">
<input type="text" name="{name($i)}" id="{name($i)}" value="{$i/@value}" class="frm"/>
</td>
</tr>
<!-- example retrieve some other data from xml -->
<xsl:for-each select="$doc/*"></xsl:for-each>
</xsl:template>


<xsl:template name="field_type_password" match="xsl:template[@name='field_type_password']">
<xsl:param name="i"/>
<tr>
<xsl:call-template name="controlset_caption">
<xsl:with-param name="i" select="$i"/>
</xsl:call-template>
<td class="inp">
<input type="password" name="{name($i)}" id="{name($i)}" value="{$i/@value}" class="frm"/>
</td>
</tr>
</xsl:template>


   <xsl:template name="caller">
       <xsl:param name="n"/>
       <xsl:param name="i"/>
       <xsl:apply-templates select="document('')/*/xsl:template[@name=$n]">
           <xsl:with-param name="i" select="$i"/>
       </xsl:apply-templates>
   </xsl:template>

<xsl:template match="/">
<xsl:for-each select="/document/*">
<xsl:call-template name="caller">
<xsl:with-param name="n" select="concat('field_type_', @mode)"/>
<xsl:with-param name="i" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>



of course, in these templates can be more complex logic, to access to source XML I use global variable $doc
I do not see how I can replace call to these templates with variables


Current Thread