2 Replies Latest reply on Mar 17, 2013 12:49 PM by BKBK

    XSLT passing two parameters in URL with ColdFusion

    Man_Hunt

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


      This is my XSLT 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"/>&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

       

      <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

       

      <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:

       

      <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>