我想通過使用ColdFusion在XSLT文件中通過URL傳遞兩個參數。使用ColdFusion在URL中傳遞兩個參數的XSLT
這是我的XSLT代碼:
<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>
這是我actor_details.cfm文件
<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>
這是基於這樣的我actor_details.xsl文件
<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>
movieID和actorID通過URL傳遞,actor_details頁面應該顯示演員的姓名和年齡。我對ColdFusion非常陌生,我無法弄清楚如何接收ColdFusion通過URL傳遞的參數。我在actor_details.cfm頁面上收到意外的錯誤。
我想問題在於actor_details.cfm頁面的某處,但我無法弄清楚它是什麼。
我的XML文件:
<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>
在您的操作頁面上執行。 –
2013-03-16 00:43:40
好吧,我已經完成了,它爲第一個演員顯示「結構actorID 1,MovieID 1」。如果我點擊其他名稱,它會根據actorID和movieID正確顯示結構。所以它似乎工作,但我仍然在下面意想不到的錯誤。我不知道爲什麼。 – Alex 2013-03-16 00:51:09
另外,如果您沒有穩健的調試輸出和日誌記錄,請在您的開發服務器的管理員中打開它,它將對您有很大的幫助。確保選擇應用程序,會話,CGI範圍輸出。它會減慢你的頁面,但你只能打開你的IP和開發服務器。 – 2013-03-16 01:16:31