RE: [xsl] How to call a template with a param

Subject: RE: [xsl] How to call a template with a param
From: "Arun Sinha" <arunsinha666@xxxxxxxxxxx>
Date: Thu, 11 Nov 2004 12:15:43 +0000
Hi,

I guess the problem is the variable name with call-template.

If you do the following :-

<xsl:call-template name="sRoot-srec1"> <!--PROCESSING STOPS HERE-->

Then there is no error reported.

Cheers.

Arun


From: Manpreet Singh <singhm@xxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] How to call a template with a param
Date: Thu, 11 Nov 2004 17:14:21 +0530

Hi,

I have the following source xml.

<sRoot>
 <srec1>
  <sleaf1>123</sleaf1>
 </srec1>
</sRoot>

Following is my target structure

<tRoot>
 <trec1>
  <tleaf1>456</tleaf1>
 </trec1>
</tRoot>

I have written the following xsl to convert the source structure to target
structure.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="/">
 <tRoot>
  <xsl:call-template name="exception">
   <xsl:with-param name="xpath" select="sRoot/srec1"/>
   <xsl:with-param name="str-xpath" select="'sRoot-srec1'"/>
  </xsl:call-template>
 </tRoot>
</xsl:template>
<xsl:template name="exception">
 <xsl:param name="xpath"/>
 <xsl:param name="str-xpath"/>
 <xsl:choose>
  <xsl:when test="count($xpath)=0">
 <!--	This call-template statement should be executed in case if my
	source has an incomplete structure (or to say in other words,
	the xpath does not exist in my source xml)
	and the template following this one should get executed-->

<xsl:call-template name="$str-xpath"> <!--PROCESSING STOPS HERE-->

    <xsl:with-param name="xpath" select="''"/>
   </xsl:call-template>
  </xsl:when>
  <xsl:otherwise>
   <xsl:apply-templates select="$xpath">
    <xsl:with-param name="xpath" select="$str-xpath"/>
   </xsl:apply-templates>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>
<xsl:template match="sRoot/srec1" name="sRoot-srec1">
 <xsl:param name="xpath"/>
 <trec1>
  <xsl:choose>
   <xsl:when test="$xpath!=''">
    <xsl:for-each select="sleaf1">
     <tleaf1>
      <xsl:value-of select="."/>
     </tleaf1>
    </xsl:for-each>
   </xsl:when>
   <!-- In case the call to this template comes from call-template
 	the following xsl:otherwise clause should get executed-->
   <xsl:otherwise>
    <tleaf1/>
   </xsl:otherwise>
  </xsl:choose>
 </trec1>
</xsl:template>
</xsl:stylesheet>

The code in the above xsl should work even if a particular node is not
found in the source xml. For example, if i use this xsl to parse the
following xml i should get the target structure correctly even if the
nodes are missing in the source.

Specimen:
<sRoot/>

My processing of xsl stops abruptly at the above mentioned point in the xsl.

Any ideas why? If yes then is there a way out.

Regards
Manpreet Singh


_________________________________________________________________
Millions of active and validated profiles. http://www.bharatmatrimony.com/cgi-bin/bmclicks1.cgi?74 Find your match on BharatMatrimony.com


Current Thread