#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    XSLT passing two parameters in URL with ColdFusion


    I am trying to pass two parameters through URL in XSLT file by using ColdFusion.

    This is my XSLT code:

    Code:
    <xsl:template match="/">
        <xsl:text>Actors: </xsl:text>
        <xsl:apply-templates select="/movies/movie/actors/actor/name"/>
    </xsl:template>
    
    <xsl:template match="name">
          <xsl:element name="a">
              <xsl:attribute name="href">actor_details.cfm?movieID=<xsl:value-of select="../../../@movieID"/>&amp;actorID=<xsl:value-of select="../@actorID"/></xsl:attribute>
              <xsl:value-of select="." />
          </xsl:element>
          <xsl:element name="br" />
    </xsl:template>
    This is my actor_details.cfm file

    Code:
    <cfset MyXmlFile = Expandpath("test.xml")>
    <cffile action="READ" variable="xmlInput"  file="#MyXmlFile#">
    <cfset MyXslFile = Expandpath("actor_details.xsl")>
    <cffile action="READ" variable="xslInput"  file="#MyXslFile#">
    
    <cfset xslParam = StructNew() >
    <cfset xslParam["movieID"] = "#url.movieID#" >
    
    <cfset xmlOutput = XMLTransform(xmlInput, xslInput, xslParam )>
    <!--- data is output --->
    <cfcontent type="text/html" reset="yes">
    <cfoutput>#xmloutput#</cfoutput>
    And this is my actor_details.xsl file

    Code:
    <xsl:param name="movieID"/>
    
    <xsl:template match="/">
        <title>Actor details</title>
        <xsl:apply-templates select="/movies/movie[@movieID=$movieID]/actors/actor[@actorID=$actorID]"/>
    </xsl:template>
    
    <xsl:template match="actor">
        <xsl:text>Name: </xsl:text>
        <xsl:value-of select="name"/>
        <xsl:element name="br"/>
        <xsl:text>Age: </xsl:text>
        <xsl:value-of select="age"/>
        <xsl:element name="br"/>
    </xsl:template>
    So based on the movieID and actorID passed through the URL, the actor_details page should display the actor's name and age. I am very new to ColdFusion and I can't figure out how to receive parameters passed through the URL with ColdFusion. I get unexpected error on the actor_details.cfm page.

    I think the problem lies somewhere in actor_details.cfm page, but I just can't figure out what it is.

    My XML file:

    Code:
    <movie movieID="1">
        <actors>
            <actor actorID="1"> 
                <name>Bob</name>
                <age>23</age>
            </actor>
    
            <actor actorID="2"> 
                <name>Jack</name> 
                <age>25</age>
            </actor>
    
            <actor actorID="3"> 
                <name>James</name>
                <age>38</age>
            </actor>
        </actors>   
    </movie>
    
    <movie movieID="2">
        <actors>
            <actor actorID="1"> 
                <name>Mike</name>
                <age>19</age>
            </actor>
    
            <actor actorID="2"> 
                <name>Daniel</name>
                <age>29</age>
            </actor>
    
            <actor actorID="3"> 
                <name>Phil</name> 
                <age>41</age>
            </actor>
        </actors>   
    </movie>
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0
    I have fixed the problem by adding
    Code:
    <cfset xslParam["actorID"] = "#url.actorID#" >
    to my CFM file and
    Code:
    <xsl:param name="actorID"/>
    to my XSL file.

IMN logo majestic logo threadwatch logo seochat tools logo