call template in another stylesheet with params

Hi!

I’ve got one stylesheet (Room.xsl) with the template “Room” and another (Components.xsl) with the template “Components”. Now I try to call the template “Components” from the template “Room” and I want to use a param called “componentID” in the template “Components”.

What is wrong here?

This is the xml:

  
<?xml version="1.0"?>
<house>
	<room_list>
		<room ID="1">
			<name>kitchen</name>
			<component-ID-list>
				<componentID>12</componentID>
				<componentID>13</componentID>
				<componentID>14</componentID>
				<componentID>15</componentID>
			</component-ID-list>
		</room>
		<room ID="2">
			<name>floor</name>
			<component-ID-list>
				<componentID>10</componentID>
				<componentID>15</componentID>
				<componentID>11</componentID>
				<componentID>13</componentID>
			</component-ID-list>
		</room>
	</room_list>
	<component_list>
		<component ID="10">
			<type>wall</type>
		</component>
		<component ID="11">
			<type>no</type>
		</component>
		<component ID="12">
			<type>roof</type>
		</component>
		<component ID="13">
			<type>standard</type>
		</component>
		<component ID="14">
			<type>wall</type>
		</component>
		<component ID="15">
			<type>no</type>
		</component>
	</component_list>
</house>
</pre> <BR><BR>This is the Room.xsl:<BR> <pre class="ip-ubbcode-code-pre">  
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="xml" indent="yes" version="1.0"/>

	<xsl:include href="Component.xsl"/>

	<xsl:template name="Room" match="/">
		<xsl:text>Room: </xsl:text><xsl:value-of select="house/room_list/room/name"/>
		<xsl:text>Components: </xsl:text>
		<xsl:for-each select="house/room_list/room/component-ID-list/componentID">
			<xsl:call-template name="Component">
				<xsl:with-param name="componentID" select="."/>
			</xsl:call-template>
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>
</pre> <BR><BR>Now I try to use componentID in the Components Template:<BR><BR>First way:<BR> <pre class="ip-ubbcode-code-pre">  
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:template name="Components" match="house/component_list/component[@ID='$componentID']">
		<xsl:param name="componentID"/>
		<xsl:text>- </xsl:text><xsl:value-of select="type"/>
	</xsl:template>
</xsl:stylesheet>
</pre> <BR><BR>Second way:<BR> <pre class="ip-ubbcode-code-pre"> 
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:template name="Components" match="house/component_list/component">
		<xsl:param name="componentID"/>
		<xsl:if test="@ID='$componentID'">
			<xsl:text>- </xsl:text><xsl:value-of select="type"/>
		</xsl:if>
	</xsl:template>

</xsl:stylesheet>
 



Why doesn’t it work?
Greetings

Your template name is “Components”, while you’re calling template with name “Component” (missing ‘s’)

Hi

when combined in a single stylesheet, the following solution works:

<xsl:stylesheet version=“1.0” xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”>
<xsl:output method=“xml” indent=“yes” version=“1.0”/>

<xsl:template name=“Room” match="/">
xsl:textRoom: </xsl:text><xsl:value-of select=“house/room_list/room/name”/>
xsl:textComponents: </xsl:text>
<xsl:for-each select=“house/room_list/room/component-ID-list/componentID”>
componentId=<xsl:value-of select="."/>
<xsl:apply-templates select="/house/component_list/component[@ID=.]"/>
</xsl:for-each>
</xsl:template>

<xsl:template match=“component”>
xsl:text- </xsl:text><xsl:value-of select=“type”/>
</xsl:template>

</xsl:stylesheet>

Note that you had a type in the template name in your original approach: “component(s)”.

Cheers
Uli

Hi Uli,

in a single stylesheet everything works, I tested it before. Thats not the problem. What I post here is only a little part of my xml. So when I write everything from the whole xml in only one stylesheet I become so many lines, I could not find anything there. This is why I try to split the code into several stylesheets. Isn’t that possible???

Greetings