Subject: Re: [xsl] compact code using loop From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Wed, 19 Mar 2008 14:09:26 +0530 |
Here is a possible solution. You can write a named template as below to abstract generating the 'item' structure. <xsl:template name="printItem"> <xsl:param name="type" /> <xsl:param name="value" /> <!-- Add more parameters if you want --> <item> <type><xsl:value-of select="$type" /></type> <value><xsl:value-of select="$value" /></value> </item> </xsl:template> Now you can call this template with appropriate parameter values wherever you want in the stylesheet (using xsl:call-template instruction). On 3/19/08, Mansour <mansour77@xxxxxxxxx> wrote: > I have repetitive code in my xslt. This code produces a list and does > not depend on the input xml. I am wondering if there is a way to > minimize this code. I can do it through for-each, but the element are in > the xslt file and not in the input xml, so I can not use the 'select='. > For example, I need to generate this code regardless of the input xml: > > <item> > <type>type1</type> > <value>val1</value> > </item> > <item> > <type>type2</type> > <value>val2</value> > </item> > <item> > <type>type3</type> > <value>val3</value> > </item> > > > Of course I can use this directly in my xsl file, but there's more item. > So the code is too long. And there are more tags for the item. Does that > make things clear? -- Regards, Mukul Gandhi
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] compact code using loop, Mansour | Thread | Re: [xsl] compact code using loop, Andrew Welch |
Re: [xsl] push-pull, Mukul Gandhi | Date | Re: [xsl] compact code using loop, Andrew Welch |
Month |