Forum Moderators: open

Message Too Old, No Replies

xsl url variable

xsl programming

         

gomez milano

1:44 pm on Sep 28, 2005 (gmt 0)

10+ Year Member



hi is it possible do that:

myxslfile.xsl?product=ice

<xsl:if $product="ice">
---
----

i try on coldfusion server but i dont know jow get url parameter... in xsl tanx

athinktank

5:14 pm on Sep 30, 2005 (gmt 0)

10+ Year Member



I do not believe that xslt has something to do this ( wish there was so one could port code easier), but there is a way.

You need to get the variable the same way you would get it via coldfusion, then set it in xslt.

so,
[code]
<xsl:variable name="product">
... put the cold fusion code to extract the url parameter here
</xsl:variable>

<xsl:if test="$product='ice'">
...do something
</xsl:if>

gomez milano

1:49 pm on Oct 1, 2005 (gmt 0)

10+ Year Member



sorry but dont work......

athinktank

3:57 pm on Oct 3, 2005 (gmt 0)

10+ Year Member



could you please post your code so that I can take a look. thanks.

gomez milano

4:24 pm on Oct 3, 2005 (gmt 0)

10+ Year Member



<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">

<xsl:template match="<cfoutput>#URL.prodottoID#</cfoutput>">
<div id="Scheda">
<div class="intestazione">
<img src="{scheda/intestazione/logo}" class="iileft"></img>
<h2><xsl:value-of select="scheda/intestazione/prodotto"/></h2>
<h3><xsl:value-of select="scheda/intestazione/titolo"/></h3>
<span><xsl:value-of select="scheda/intestazione/dosaggio"/></span>
<h3><img src="/dulcis/img/confezione.gif" width="43" height="35" />
<xsl:value-of select="scheda/intestazione/confezione"/></h3>
</div>
<div class="line"><img src="../../img/clear.gif" alt="" /></div>
<div class="preparazione"><xsl:value-of select="scheda/titolo"/></div>
<xsl:for-each select="scheda/preparazione/fase">
<div class="fasi"><img src="{img}" class="iileft"></img>
<span><xsl:value-of select="descr"/></span>
</div>
<div class="line"><img src="../../img/clear.gif" alt="" /></div>
</xsl:for-each>



</div>


</xsl:template>

</xsl:template>
</xsl:stylesheet>

athinktank

5:22 pm on Oct 3, 2005 (gmt 0)

10+ Year Member



could you also post your xml or data (are you using an xml file, a data source, etc)? with that information, I can put together a simple example of how to do this. I should have asked for that before. If have other files in the mix too, please post them too. Thanks and I hope I can help

athinktank

10:47 pm on Oct 3, 2005 (gmt 0)

10+ Year Member



i worked up an example that works with 7
you will need to change the paths to be absolute to your environment. this is my first cold fusion page, so, please be kind.

test.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<products>
<product id='1'>
<name>wid</name>
</product>
<product id='2'>
<name>git</name>
</product>
</products>

test.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="productId" select="0" />
<xsl:template match="/">
<!-- display the product info based on what was passed to us -->
<xsl:text>Here is the name of product #</xsl:text><xsl:value-of select="$productId"/><xsl:text>-</xsl:text>
<xsl:value-of select="products/product[@id=$productId]/name" />
</xsl:template>
</xsl:stylesheet>

test.cfml
<cffile action="read" file="/Users/paul/Applications/ColdFusionMX7/wwwroot/test.xsl" variable="xmltrans">
<cfset xmldoc = XmlParse("/Users/paul/Applications/ColdFusionMX7/wwwroot/test.xml")>
<cfset productId = #Url.productId#>
<cfscript>
variables.theXslParams = StructNew();
StructInsert(variables.theXslParams, "productId", productId);
WriteOutput(XmlTransform(xmldoc, xmltrans, variables.theXslParams));
</cfscript>

then call test.cfml. i hope this works. if not, sticky me and we'll work it out then post the solution.

gomez milano

1:57 pm on Oct 7, 2005 (gmt 0)

10+ Year Member



dont work my file are :

<cfinvoke component="component.content_menu" method="Content" returnvariable="xmlcontent" xmlFile="prodotti_#session.lang#" prodottoID="#URL.prodottoID#" xslFile="scheda" xPath="D:\Inetpub\#*$!xxx\xml_files\">
<cfoutput>#xmlContent#</cfoutput>

<cffunction name="Content" access="public" returntype="string">
<cfargument name="xmlFile" type="string" required="yes">
<cfargument name="xslFile" type="string" required="yes">
<cfargument name="xPath" type="string" required="yes">
<cfargument name="prodottoID" type="string" required="no">
<cffile action="read" file="#xPath##xmlFile#.xml" variable="xmldoc">
<cffile action="read" file="#xPath##xslFile#.xsl" variable="xsldoc">
<cfset xmlDoc= XmlParse(xmldoc)>
<cfset xmlTranslation = XmlParse(xsldoc)>
<cfif isDefined("prodottoID")>
<cfscript>
variables.theXslParams = StructNew();
StructInsert(variables.theXslParams, "prodottoId", prodottoId);
</cfscript>
<cfset xmlContent=XmlTransform(xmldoc, xsldoc, variables.theXslParams)>
<cfelse>
<cfset xmlContent = XmlTransform(xmlDoc,xmlTranslation) >
</cfif>
<cfreturn xmlContent >
</cffunction>

my xsl

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="prodottoID" />
<xsl:template match="/">
<xsl:value-of select="$prodottoID"/>
<div id="Scheda">
<div class="intestazione">
<img src="{dessert/scheda[@id=$prodottoID]/intestazione/logo}" class="iileft"></img>
<h2><xsl:value-of select="dessert/scheda[@id=$prodottoID]/intestazione/prodotto"/></h2>
<h3><xsl:value-of select="dessert/scheda[@id=$prodottoID]/intestazione/titolo"/></h3>
<span><xsl:value-of select="dessert/scheda[@id=$prodottoID]/intestazione/dosaggio"/></span>
<h3><img src="/dulcis/img/confezione.gif" width="43" height="35" />
<xsl:value-of select="dessert/scheda[@id=$prodottoID]/intestazione/confezione"/></h3>
</div>
<div class="line"><img src="../../img/clear.gif" alt="" /></div>
<div class="preparazione"><xsl:value-of select="dessert/scheda[@id=$prodottoID]/titolo"/></div>
<xsl:for-each select="dessert/scheda[@id=$prodottoID]/preparazione/fase">
<div class="fasi"><img src="{img}" class="iileft"></img>
<span><xsl:value-of select="descr"/></span>
</div>
<div class="line"><img src="../../img/clear.gif" alt="" /></div>
</xsl:for-each>



</div>