Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

apply template with variable

8 views
Skip to first unread message

Philipp Kraus

unread,
Feb 27, 2013, 9:11:46 AM2/27/13
to
Hello,

I have got a problem with a query, that is passend by a parameter.
See this two templates


<xsl:call-template name="section">
<xsl:with-param name="query">
<xsl:value-of select="sectiondef[@kind='public-func']"/>
</xsl:with-param>
</xsl:call-template>


<xsl:template name="section">
<xsl:param name="query" required="yes"/>
<xsl:apply-templates select="sectiondef[@kind='public-func']">
<xsl:sort select="name"/>
</xsl:apply-templates>

do other things
</xsl:template>

I have set up the query on the second template equal / fixed, this
works, if I now
subsitute the select query on apply to

<xsl:template name="section">
<xsl:param name="query" required="yes"/>
<xsl:apply-templates select="$query">
<xsl:sort select="name"/>
</xsl:apply-templates>

do other things
</xsl:template>

The apply results 0 nodes and this does not work anymore. So I would
push a query to the template and call in the template an apply with
this query.

Thanks

Phil

Martin Honnen

unread,
Feb 27, 2013, 10:43:36 AM2/27/13
to
Philipp Kraus wrote:

> I have got a problem with a query, that is passend by a parameter.
> See this two templates
>
>
> <xsl:call-template name="section">
> <xsl:with-param name="query">
> <xsl:value-of select="sectiondef[@kind='public-func']"/>
> </xsl:with-param>

I think you simply want to use the "select" attribute of "with-param", as in
<xsl:with-param name="query"
select="sectiondef[@kind='public-func']"/>

Then the below template should work.

> <xsl:template name="section">
> <xsl:param name="query" required="yes"/>
> <xsl:apply-templates select="$query">
> <xsl:sort select="name"/>
> </xsl:apply-templates>
>
> do other things
> </xsl:template>

But seeing all those named template being called with parameters I
wonder whether you could not simply use template matching, perhaps with
modes instead, to leverage the power of XSLT.



Philipp Kraus

unread,
Feb 27, 2013, 12:14:38 PM2/27/13
to
Thanks for your answer, I will test it.
The solution is, that I use the call name, that I mixed up matching &
calling templates. I'm using XSLT for creating a plain text output
and I have created the name-matching templates for structures that are
always used like function in other languages eg
the calling templates generates a header
--- my header ---
and the matching templates fills the section, in this case the section
templates creates the full plaintext section (header + content)

Phil

Philipp Kraus

unread,
Feb 27, 2013, 8:03:36 PM2/27/13
to
On 2013-02-27 16:43:36 +0100, Martin Honnen said:

> Philipp Kraus wrote:
>
>> I have got a problem with a query, that is passend by a parameter.
>> See this two templates
>>
>>
>> <xsl:call-template name="section">
>> <xsl:with-param name="query">
>> <xsl:value-of select="sectiondef[@kind='public-func']"/>
>> </xsl:with-param>
>
> I think you simply want to use the "select" attribute of "with-param", as in
> <xsl:with-param name="query"
> select="sectiondef[@kind='public-func']"/>
>
> Then the below template should work.

Thanks with the select call it works

Phil

0 new messages