• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

XSLT passing two parameters in URL with ColdFusion

Guest
Mar 15, 2013 Mar 15, 2013

Copy link to clipboard

Copied

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>





Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 16, 2013 Mar 16, 2013

Copy link to clipboard

Copied

I have fixed the problem by adding <cfset xslParam["actorID"] = "#url.actorID#" > to my CFM file and <xsl:param name="actorID"/> to my XSL file.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 17, 2013 Mar 17, 2013

Copy link to clipboard

Copied

LATEST

Good. Then please kindly mark the question as answered.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation