apply template with variable

Discussion in 'XML' started by Philipp Kraus, Feb 27, 2013.

  1. 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
     
    Philipp Kraus, Feb 27, 2013
    #1
    1. Advertising

  2. 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.
     
    Martin Honnen, Feb 27, 2013
    #2
    1. Advertising

  3. 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">
    >> <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.


    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, Feb 27, 2013
    #3
  4. 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
     
    Philipp Kraus, Feb 28, 2013
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Siegl
    Replies:
    1
    Views:
    966
    Marrow
    Jul 18, 2003
  2. Vijay singh
    Replies:
    1
    Views:
    436
    Martin Honnen
    Nov 4, 2004
  3. Chris Theis
    Replies:
    2
    Views:
    480
    Chris Theis
    Jul 24, 2003
  4. tom_usenet
    Replies:
    0
    Views:
    539
    tom_usenet
    Jul 24, 2003
  5. Martin Honnen

    Re: string concat with apply template

    Martin Honnen, Mar 3, 2013, in forum: XML
    Replies:
    1
    Views:
    653
    Philipp Kraus
    Mar 3, 2013
Loading...

Share This Page