xslt - xsl:if or xsl:applytemplate which one has better memroy usage -


lets have input following.

<country>     <name>countryname</name>     <capital>captialname</capital>     <population>19000</population> </country> 

i'm trnsforming element names lets upper code using xsl. child elements of country may not occur sometimes. can write transformation follows.

<xsl:template match="country">     <xsl:element name="country">         <xsl:apply-templates select="name" />         <xsl:apply-templates select="capital" />         <xsl:apply-templates select="population" />     </xsl:element> </xsl:template>  <xsl:template match="name">     <xsl:element name="name">         <xsl:value-of select="." />     </xsl:element> </xsl:template>  <xsl:template match="capital">     <xsl:element name="capital">         <xsl:value-of select="." />     </xsl:element> </xsl:template>  <xsl:template match="population">     <xsl:element name="population">         <xsl:value-of select="." />     </xsl:element> </xsl:template> 

or can follows.

<xsl:template match="country"> <xsl:element name="country">     <xsl:if test="name">         <xsl:element name="name">             <xsl:value-of select="." />         </xsl:element>     </xsl:if>     <xsl:if test="capital">         <xsl:element name="capital">             <xsl:value-of select="." />         </xsl:element>     </xsl:if>     <xsl:if test="population">         <xsl:element name="population">             <xsl:value-of select="." />         </xsl:element>     </xsl:if> </xsl:element> 

i'm wondering way it'd use less memory. actual code have goes around 7 levels deep inside templates. need know if don't use use templates simple elements if improve memory usage.

as per understanding first 1 good. change:

<xsl:apply-templates select="name" />         <xsl:apply-templates select="capital" />         <xsl:apply-templates select="population" /> 

to

<xsl:apply-templates/> 

only , don't worry child element if not coming xslt take care it.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -