I have written a DWT which is creating an XML as below:-
<?xml version="1.0" encoding="utf-8"?><episodes><episode>
<episode_id>EPS_7208_7205_56</episode_id>
<title>Episode 56</title>
<media_links>
<media_link>
<asset_id></asset_id>
<media_filepath>\Entertainment\TV Shows\TV Show 56.mp4</media_filepath>
<media_type>mp4</media_type>
</media_link>
</media_links></episode><episode><episode_id>EPS_7208_7205_57</episode_id>
<title>Episode 2</title>
<media_links>
<media_link>
<asset_id>Asset_EPS_56</asset_id>
<media_filepath>\Entertainment\TV Shows\TV Show 1.mp4</media_filepath>
<media_type>mp4</media_type>
</media_link>
</media_links></episode><episode><episode_id>EPS_7208_7205_58</episode_id>
<title>Episode 2</title>
<media_links>
<media_link>
<asset_id>Asset_EPS_57</asset_id>
<media_filepath>\Entertainment\TV Shows\TV Show 1.mp4</media_filepath>
<media_type>mp4</media_type>
</media_link>
</media_links></episode></episodes>
DWT Code:-
<?xml version="1.0" encoding="utf-8"?><episodes><!-- TemplateBeginRepeat name="episodes" --><episode> <episode_id>EPS_@@GetIdFromTcmUri(Component.ID)@@_@@episode_number@@</episode_id>
@@SetVariable('EpisodeNumber', episode_number)@@
<title>@@title@@</title>
<media_links>
<!-- TemplateBeginRepeat name="media_links" -->
<media_link>
<asset_id>Asset_EPS_@@GetVariable('EpisodeNumber')@@</asset_id>
<media_filepath>@@media_filepath@@</media_filepath>
<media_type>@@media_type@@</media_type>
</media_link>
<!-- TemplateEndRepeat -->
</media_links></episode><!-- TemplateEndRepeat --></episodes>
I calling template callable methods:-
/// <summary>
/// Sets a varialbe in the package to the name and value specifed. Also removes any other variable that was set with the same name before.
/// </summary>
/// <param name="variableName">Name of the varialbet</param>
/// <param name="value">Value of the variable</param>
[TemplateCallable()]
public string SetVariable(string variableName, string value)
{
//Remove the old variable and set the new variable
m_engine.PublishingContext.RenderContext.ContextVariables.Remove(variableName);
m_engine.PublishingContext.RenderContext.ContextVariables.Add(variableName, value);
return String.Empty;
}
/// <summary>
/// Gets a variable from the publishing context.
/// </summary>
/// <param name="variableName">Name of the variable</param>
[TemplateCallable()]
public string GetVariable(string variableName)
{
//Get the variable
try
{
return m_engine.PublishingContext.RenderContext.ContextVariables[variableName].ToString();
}
catch
{
return String.Empty;
}
}
IN the asset_id node I want the value of episode number which was set initially as soon as episodes loop started. But the value which I am expecting for asset_id node of an episode is getting written in the asset_id node of episode which is next to it in xml. Can you please tell where I am wrong?
episode_number
coming from exactly, the way I read your DWT TBB it seems to be in the package, so you could simply use@@episode_number@@
but I might be missing something here? Perhaps you need to look at my answer here for options on how to use multiple value parameters in the package?