Jump to content

call-template


Guest sullivan

Recommended Posts

Guest sullivan

Hi everyoneFirst of all, this question probably is very noob, but I'm stuck so...Well... I have a piece of code looking like this:

<ROOT> <xsl:template match='/'>  <TAG1>   <xsl:for-each select="RECORDS/R">    <TAG2 Label="a label here">     <xsl:choose>      <xsl:when test="test1 here">       <xsl:call-template name="t1">        <xsl:with-param name="record" select="." />        </xsl:call-template>      </xsl:when>      <xsl:when test="test2 here">       <xsl:call-template name="t2">        <xsl:with-param name="record" select="." />        </xsl:call-template>      </xsl:when>     </xsl:choose>    </TAG2>   </xsl:for-each>  </TAG1> </xsl:template> <xsl:template name="t1">  <xsl:param name="record" />   <TAG3>  ...  </TAG3> </xsl:template> <xsl:template name="t2">  <xsl:param name="record" />   <TAG3>  ...  </TAG3> </xsl:template> ... (some records down here)</ROOT>

and after processing, I'm getting this:

<TAG1> <TAG2 Label="a label here"/> <TAG2 Label="a label here"/></TAG1>

instead of what I need, which is:

<TAG1> <TAG2 Label="a label here">  <TAG3>  ...  </TAG3> </TAG2> <TAG2 Label="a label here">  <TAG3>  ...  </TAG3> </TAG2></TAG1>

I suspect (not to say assure) that my mistake is in that <xsl:call-template name="t1">, because I'm following a model that looked exactly the same except that it didn't used call-template, and it works fine in the destiny application.But I have tryed everything on that call-template tag, and I don't get it right!it should be a simple mistake!thanks to anyone that could give me some help!

Link to comment
Share on other sites

I actually didn't knew it's possible to have a template inside a template. Wow :) . As for what's your mistake... hm... I'm not sure But I think the template is called only if it's defined above the call-template element.

Link to comment
Share on other sites

I think it's supposed to be <apply-templates select="t1" /> rather than using call-template.If you use it this way, then you can define three templates for the same element within your xsl document and use choose to apply the appropriate template.Alternatively, you could put the criteria within the template so that it formats differently for different properties of your root element, I don't know if one is better than the other, because you probably have to write the same amount of code for both.Then you can base your template on <xsl:template match="insert element name here" /> and you don't have to worry about when the formatting will be applied.I hope this helps, but if not then I apologise.Dooberry is still in the top ten on Yetisports.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...