[xsl] RE: Getting values from different templates

Subject: [xsl] RE: Getting values from different templates
From: T Uma Shankari <umashankari@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 10 Jan 2006 15:59:47 +0530 (IST)
Here i have pasted partial of the code. I am replacing {sub} to <sub> and {/sub} to </sub>

Code to retrieve contents before this symbol '|'
-------------------------------------------------------------

<xsl:template match="content">
     <xsl:variable name="string11">
       <xsl:value-of select="substring-before(.,'|')"/>
     </xsl:variable>
   <xsl:if test="(contains($string11,'{sub}'))">
    <xsl:call-template name="replacebeforesub">
       <xsl:with-param name="string1" select="$string11"/>
     </xsl:call-template>
  </xsl:if>
</xsl:template>

<xsl:template name="replacebeforesub">
  <xsl:param name="string1"/>
     <xsl:variable name="string11">
   <xsl:if test="(contains($string1,'{sub}'))">
    <xsl:value-of select="substring-before($string1,'{sub}')"/>
       <sub>
         <xsl:value-of select="substring-before(substring-after($string1,'{sub}'),'{/sub}')"/>
        </sub>
     <xsl:value-of select="substring-after($string1,'{/sub}' )" />
    </xsl:if>
     </xsl:variable>
    <xsl:if test="(contains($string1,'{sub}'))">
     <xsl:call-template name="replacebeforesub">
      <xsl:with-param name="string1" select="$string11"/>
    </xsl:call-template>
   </xsl:if>
   <xsl:if test=3D"not((contains($string1,'{sub}')))">
     <xsl:call-template name="replacebeforesubclose">
       <xsl:with-param name="stringfinal1" select="$string1"/>
     </xsl:call-template>
   </xsl:if>
</xsl:template>

<xsl:template name="replacebeforesubclose">
   <xsl:param name="stringfinal1"/>
   <xsl:call-template name="finalfirst">
     <xsl:with-param name="stringfirst" select="$stringfinal1"/>
   </xsl:call-template>
</xsl:template>



Here is the code to retrieve contents in btw these symbols '|' '\'
-------------------------------------------------------------------
<xsl:template match="content">
     <xsl:variable name="string1">
       <xsl:value-of select="substring-before(substring-after(.,'|'),'\')"/>
     </xsl:variable>
   <xsl:if test="(contains($string1,'{sub}'))">
    <xsl:call-template name="replacemidsub">
       <xsl:with-param name="string" select="$string1"/>
     </xsl:call-template>
  </xsl:if>
</xsl:template>


<xsl:template name="replacemidsub"> <xsl:param name="string"/> <xsl:if test="(contains($string,'{sub}'))"> <xsl:variable name="string1"> <xsl:value-of select="substring-before($string,'{sub}')"/> <sub> <xsl:value-of select="substring-before(substring-after($string,'{sub}'),'{/sub}')"/> </sub> <xsl:value-of select="substring-after($string,'{/sub}' )" /> </xsl:variable> <xsl:call-template name="replacemidsub"> <xsl:with-param name="string" select="$string1"/> </xsl:call-template> </xsl:if> <xsl:if test="not((contains($string,'{sub}')))"> <xsl:call-template name="replacemidsubclose"> <xsl:with-param name="stringfinal" select="$string"/> </xsl:call-template> </xsl:if> </xsl:template>

<xsl:template name=3D"replacemidsubclose">
  <xsl:param name=3D"stringfinal"/>
   <xsl:call-template name="finalmidstring">
     <xsl:with-param name="stringmid" select="$stringfinal"/>
   </xsl:call-template>
</xsl:template>


---------------------------------------------------------


code to retrieve contents after this symbol '\'
-------------------------------------------------------

<xsl:template match="content">
     <xsl:variable name="string1">
       <xsl:value-of select="substring-before(substring-after(.,'|'),'\')"/>
     </xsl:variable>
   <xsl:if test="(contains($string1,'{sub}'))">
    <xsl:call-template name="replacemidsub">
       <xsl:with-param name="string" select="$string1"/>
     </xsl:call-template>
  </xsl:if>
</xsl:template>


<xsl:template name="replacemidsub"> <xsl:param name="string"/> <xsl:if test="(contains($string,'{sub}'))"> <xsl:variable name="string1"> <xsl:value-of select="substring-before($string,'{sub}')"/> <sub> <xsl:value-of select="substring-before(substring-after($string,'{sub}'),'{/sub}')"/> </sub> <xsl:value-of select="substring-after($string,'{/sub}' )" /> </xsl:variable> <xsl:call-template name="replacemidsub"> <xsl:with-param name="string" select="$string1"/> </xsl:call-template> </xsl:if> <xsl:if test="not((contains($string,'{sub}')))"> <xsl:call-template name="replacemidsubclose"> <xsl:with-param name="stringfinal" select="$string"/> </xsl:call-template> </xsl:if> </xsl:template>

<xsl:template name="replacemidsubclose">
  <xsl:param name="stringfinal"/>
   <xsl:call-template name="finalendstring">
     <xsl:with-param name="stringend" select="$stringfinal"/>
   </xsl:call-template>
</xsl:template>


--------------------------------------------------------------


my input file looks like this.

<content>statement1 |option1\ statement2 </content>
<content>statement1 }option1\ statement2 </content>

Current Thread