[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
RE: How to call a template with a param
Subject: RE: 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: 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|