RE: [xsl] using call-template to call template from another xsl

Subject: RE: [xsl] using call-template to call template from another xsl
From: Wate@xxxxxxxxx
Date: Fri, 4 May 2001 09:39:46 -0400
thankx
-shirish
-----Original Message-----
From: John Wang [mailto:jwang@xxxxxxxxxxx]
Sent: Friday, May 04, 2001 9:08 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] using call-template to call template from another xsl


you have small mistake with the names you are using:
here is the xml:
<?xml version="1.0"?>
<order>
	<admin>
		<pon>1234</pon>
		<name>Shirish Wate</name>
	</admin>
	<billing>
		<firstname>Shirish</firstname>
		<lastname>Wate</lastname>
	</billing>
</order>

here is master.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:import href="admin.xsl">
	</xsl:import>
	<xsl:import href="billing.xsl">
	</xsl:import>
	<xsl:template match="/">
		<myorder>
			<xsl:apply-templates/>
		</myorder>
	</xsl:template>
	<xsl:template match="/order/admin">
		<xsl:call-template name="tmpadmin"/>
	</xsl:template>
	<xsl:template match="/order/billing">
		<xsl:call-template name="tmpbill"/>
	</xsl:template>
</xsl:stylesheet>

here is admin.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
	<xsl:template name="tmpadmin">
		<adminsection>
			<xsl:if test="pon">
				<purchaseordernumber>
					<xsl:value-of select="pon"/>
				</purchaseordernumber>
			</xsl:if>
			<xsl:if test="name">
				<myname>
					<xsl:value-of select="name"/>
				</myname>
			</xsl:if>
		</adminsection>
	</xsl:template>
</xsl:stylesheet>

here is billing.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
	<xsl:template name="tmpbill">
		<billingsection>
			<xsl:if test="firstname">
				<myfirstname>
					<xsl:value-of select="firstname"/>
				</myfirstname>
			</xsl:if>
			<xsl:if test="lastname">
				<mylastname>
					<xsl:value-of select="lastname"/>
				</mylastname>
			</xsl:if>
		</billingsection>
	</xsl:template>
</xsl:stylesheet>

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Wate@xxxxxxxxx
Sent: Thursday, May 03, 2001 12:47 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] using call-template to call template from another xsl

hi

   my xml is

<order>
        <admin>
                <pon>
                        1234
                </pon>
                <name>
                        Shirish Wate
                </name>
        </admin>
        <billing>
                <firstname>
                        Shirish
                </firstname>
                <lastname>
                        Wate
                </lastname>
        </billing>
</order>


i want the output to something like this

<myorder>
        <adminsection>
                <purchaseordernumber>
                        1234
                </purchaseordernumber>
                <myname>
                        Shirish Wate
                </myname>
        </adminsection>
        <billingsection>
                <myfirstname>
                        Shirish
                </myfirstname>
                <mylastname>
                        Wate
                </mylastname>
        </billingsection>
</myorder>

but i want to write separate xsl for the admin and billing.
i have written three xsls master.xsl,admin.xsl and billing.xsl
----------------------------------------------------
master.xsl
---------------------------------------------------
 <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; >
        <xsl:import  href="admin.xsl"></xsl:import>
        <xsl:import  href="billing.xsl"></xsl:import>
        <xsl:template match="/order/admin">
                <myorder>
                        <xsl:call-template name="tmpadmin"/>
                        <xsl:call-template name="tmpbill"/>
                </myorder>
        </xsl:template>
</xsl:stylesheet>
----------------------------------------------------
admin.xsl
---------------------------------------------------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; >
        <xsl:output method = "xml" indent = "yes" omit-xml-declaration="yes"
/>
        <xsl:template  name="tmpadmin" >
                <adminsection>
                        <xsl:if test= "pon"
><purchaseordernumber><xsl:value-of select="pon" />
</purchaseordernumber></xsl:if>
                        <xsl:if test= "name" ><myname><xsl:value-of
select="name" /> </myname></xsl:if>
                </adminsection>
        <xsl:template>
</xsl:stylesheet>

-------------------------------------------------
billing.xsl
-------------------------------------------------

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; >
        <xsl:output method = "xml" indent = "yes" omit-xml-declaration="yes"
/>
        <xsl:template  name="tmpbill" >
                <adminsection>
                        <xsl:if test= "firstname"
><myfirstname><xsl:value-of select="firstname" /> </myfirstname></xsl:if>
                        <xsl:if test= "lastname" ><mylastname><xsl:value-of
select="lastname" /> </mylastname></xsl:if>
                </adminsection>
        <xsl:template>
</xsl:stylesheet>
-------------------------------------------------

i am getting the <adminsection> properly but  in the <billingsection> i get
empty tags <myfirstname> and <mylastname> even though the corresponding tags
are present in the input xml

can anybody help me on this.

thankx in advance
-shirish wate

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread