XSL 1.0 - Putting multiple <call-template> in one template.

RKO

New Member
I want to preface with the fact that I am still fairly fresh on the "XSL Coding" scene. But my question should be a simple one.So basically I am styling an XML output and in doing so the end user can choose 4 different layouts in the application. I have a set of template calls that transform the XML data following a . The problem is I duplicate the template calls 4 times in my XSL, once for each layout. Is there a way to consolidate this so there is one template call that runs all these other template calls? Every time I try the variables break and everything dies. Thanks in advance! Here is my code:\[code\]<xsl:template name="string-replace-all"><xsl:param name="text" /><xsl:param name="replace" /><xsl:param name="by" /><xsl:choose> <xsl:when test="contains($text, $replace)"> <xsl:value-of select="substring-before($text,$replace)" /> <xsl:value-of select="$by" /> <xsl:call-template name="string-replace-all"> <xsl:with-param name="text" select="substring-after($text,$replace)" /> <xsl:with-param name="replace" select="$replace" /> <xsl:with-param name="by" select="$by" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$text" /> </xsl:otherwise> </xsl:choose></xsl:template> <!-- Check and replace with small images --> <xsl:template name="smallimage"> <xsl:choose> <xsl:when test="photo/small and photo/small != '' "><xsl:value-of select="photo/small" /></xsl:when> <xsl:otherwise> <xsl:choose> <xsl:when test="photo/image != ''"><xsl:value-of select="photo/image" /></xsl:when> <xsl:otherwise></xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </xsl:template> *** The other templates are here as well ***<xsl:template match="/"> <xsl:choose> <xsl:when test="$display_layout = 1"> **** THIS REPEATS FOR EACH LAYOUT **** <xsl:for-each select="feed/item"> <xsl:variable name="image_size_default" select="200" /> <!-- Check For A Call To Action --> <xsl:variable name="cta"> <xsl:choose> <xsl:when test="link/cta"> <xsl:value-of select="link/cta" /> </xsl:when> <xsl:otherwise> MORE </xsl:otherwise> </xsl:choose> </xsl:variable> <!-- Get Desired Image Size --> <xsl:variable name="image_desired_width"> <xsl:choose> <xsl:when test="$image_width = ''"> <xsl:value-of select="$image_size_default" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$image_width"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <!-- Get Image Size for Medium Image to check and see if it's too small --> <xsl:variable name="image_size_checker"> <xsl:call-template name="mediumimage_size" /> </xsl:variable> <!-- Get Image Source --> <xsl:variable name="image"> <xsl:choose> <xsl:when test="$image_size_checker <= $image_desired_width"> <xsl:call-template name="largeimage" /> </xsl:when> <xsl:otherwise> <xsl:call-template name="mediumimage" /> </xsl:otherwise> </xsl:choose> </xsl:variable> <!-- Get Image Size --> <xsl:variable name="image_size"> <xsl:choose> <xsl:when test="$image_size_checker <= $image_desired_width"> <xsl:call-template name="largeimage_size" /> </xsl:when> <xsl:otherwise> <xsl:call-template name="mediumimage_size" /> </xsl:otherwise> </xsl:choose> </xsl:variable> <!-- Change Image Size --> <xsl:variable name="image_size_render"> <xsl:choose> <xsl:when test="$image_size > $image_desired_width"> <xsl:value-of select="$image_desired_width" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$image_size"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <!-- Create Variable To Keep Images from Changing Sizes Responsively --> <xsl:variable name="image_size_static"> <xsl:choose> <xsl:when test="$image_width = '' and $image_size_default >= $image_size"> max-width:<xsl:value-of select="$image_size" />px !important;</xsl:when> <xsl:when test="$image_width != ''">max-width:<xsl:value-of select="$image_size_render" />px !important;</xsl:when> <xsl:otherwise></xsl:otherwise> </xsl:choose> </xsl:variable> <!-- Add Style To Links --> <xsl:variable name="title"> <xsl:call-template name="string-replace-all"> <xsl:with-param name="text" select="title" /> <xsl:with-param name="replace" select="'link_style:null'" /> <xsl:with-param name="by" select="concat('color:',$link_color,'; font-weight:',$link_bold,'; text-decoration:',$link_underline,'; font-style:',$link_italic,'; font-size:',$link_size,';')" /> </xsl:call-template> </xsl:variable> <!-- Add Style To Links --> <xsl:variable name="description"> <xsl:call-template name="string-replace-all"> <xsl:with-param name="text" select="description" /> <xsl:with-param name="replace" select="'link_style:null'" /> <xsl:with-param name="by" select="concat('color:',$link_color,'; font-weight:',$link_bold,'; text-decoration:',$link_underline,'; font-style:',$link_italic,'; font-size:',$link_size,';')" /> </xsl:call-template> </xsl:variable> *** ALL MY TRANSFORMATIONS GO HERE **** </for-each> </xsl:when> <xsl:when test="$display_layout = 2"> *** I RUN ALL THE CALLS AGAIN *** </xsl:when> <xsl:when test="$display_layout = 3"> *** I RUN ALL THE CALLS AGAIN *** </xsl:when> <xsl:choose></xsl:template>\[/code\]
 
Back
Top