Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > apply template with variable

Reply
Thread Tools

apply template with variable

 
 
Philipp Kraus
Guest
Posts: n/a
 
      02-27-2013
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">
<xslaram 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">
<xslaram 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

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      02-27-2013
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">
> <xslaram 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.



 
Reply With Quote
 
 
 
 
Philipp Kraus
Guest
Posts: n/a
 
      02-27-2013
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.
>
>> <xsl:template name="section">
>> <xslaram 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.


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

 
Reply With Quote
 
Philipp Kraus
Guest
Posts: n/a
 
      02-28-2013
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: string concat with apply template Martin Honnen XML 1 03-03-2013 06:29 PM
Apply this Template to all the subfolders kenny Computer Support 2 10-27-2005 12:12 AM
XSLT question related to <xsl:template> and <xsl:apply-templates> Vijay singh XML 1 11-04-2004 03:42 PM
Re: A Newbie Question about template template template Chris Theis C++ 2 07-24-2003 09:42 AM
[XSLT] could not apply "apply-templates" Stefan Siegl XML 1 07-18-2003 09:43 AM



Advertisments