[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Hi Manpreet,
Why can't you replace :-
<xsl:call-template name="$str-xpath"> <!--PROCESSING STOPS HERE-->
Do you intend to call different templates based on conditions?
Cheers.
Arun
_________________________________________________________________
Protect your PC! Call in the experts! http://www.msn.co.in/security/ Click here now!
RE: [xsl] How to use string as an xpath for call-template?
Subject: RE: [xsl] How to use string as an xpath for call-template? From: "Arun Sinha" <arunsinha666@xxxxxxxxxxx> Date: Tue, 16 Nov 2004 05:12:07 +0000 |
Hi Manpreet,
Why can't you replace :-
<xsl:call-template name="$str-xpath"> <!--PROCESSING STOPS HERE-->
With :- <xsl:call-template name="sRoot-srec1"> <!--PROCESSING STOPS HERE-->
You already have a named template so no need to call it with a variable name.
Do you intend to call different templates based on conditions?
Cheers.
Arun
From: Manpreet Singh <singhm@xxxxxxxxxxx> Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx To: "'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'" <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Subject: [xsl] How to use string as an xpath for call-template? Date: Tue, 16 Nov 2004 10:04:48 +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
_________________________________________________________________
Protect your PC! Call in the experts! http://www.msn.co.in/security/ Click here now!
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] How to use extract the el, Michael Kay | Thread | [xsl] key usage and evaluate functi, DERHILLE Magalie - 8 |
[xsl] How to use string as an xpath, Manpreet Singh | Date | [xsl] key usage and evaluate functi, DERHILLE Magalie - 8 |
Month |