IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.



#Automation


#Applicationintegration
#webMethods
#Integration
 View Only
  • 1.  call template in another stylesheet with params

    Posted 11/25/04 11:09 AM

    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


    #Tamino
    #webMethods
    #API-Management


  • 2.  RE: call template in another stylesheet with params

    Posted 11/26/04 07:41 PM

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


    #Tamino
    #webMethods
    #API-Management


  • 3.  RE: call template in another stylesheet with params

    Posted 11/27/04 03:49 PM

    Hi

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

    <xsl:stylesheet version=“1.0” xmlns:xsl=“XSLT Namespace”>
    <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


    #Tamino
    #webMethods
    #API-Management


  • 4.  RE: call template in another stylesheet with params

    Posted 11/29/04 09:01 AM

    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


    #webMethods
    #Tamino
    #API-Management