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. Advertisements

  2. 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.
    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. Advertisements

  3. 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. Thanks with the select call it works

    Phil
     
    Philipp Kraus, Feb 28, 2013
    #4
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.