aalbetski Posted November 7, 2007 Share Posted November 7, 2007 I am assuming that your "error" is a lack of data appearing when you pass your parameter in.I noticed yesterday that their is a trailing space after each name after we apply the substring-before to it. You can trim the spaces using the normalize-space function. something like this: <xsl:variable name="category">Corso MS Access</xsl:variable> <xsl:for-each select="//products/product[normalize-space((substring-before(name,'(')))=$category]"> <xsl:value-of select="."/> </xsl:for-each> Link to comment Share on other sites More sharing options...
andreathedove Posted November 7, 2007 Author Share Posted November 7, 2007 The code:<?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" encoding="iso-8859-1"/> <xsl:param name="category"/> <xsl:template match="/"><xsl:variable name="cat" select="//products/product/name"/><xsl:variable name="totale" select="count(//products/product[name=$category])"/>[ <xsl:value-of select="$totale"/> ]<br /><br /><br /><table><tr><xsl:for-each select="//products/product[name=$category]"><xsl:sort select="name" data-type="text" order="ascending" /><td><a href="game.asp?gameid={name}"><b><xsl:value-of select="name"/></b></a> <br /></td> <xsl:if test="position() mod 3 = 0"> <!-- Blocco CDATA assieme a codice Javascript --> <script> <![CDATA[document.write("</tr><tr>");]]> </script> <!-- FINE Blocco CDATA assieme a codice Javascript --> </xsl:if> </xsl:for-each></tr></table></xsl:template></xsl:stylesheet> the string for the category:display.asp?cat=xxxThanks,Andrea I would like insert this line but it don't work:<xsl:for-each select="//products/product[substring-before(name,'(')=$category]">instead of<xsl:for-each select="//products/product[name=$category]">but it don't work.Andrea Link to comment Share on other sites More sharing options...
aalbetski Posted November 7, 2007 Share Posted November 7, 2007 There is nothing wrong with the XSLT code syntax. Have you tried hard-coding the param like this:<xsl:param name="category">xxx</xsl:param>If that fails, then you have an error in the XSLT. My guess is that the parameter is not getting passed to the XSLT. You will need to show the code that does that. Link to comment Share on other sites More sharing options...
andreathedove Posted November 7, 2007 Author Share Posted November 7, 2007 I would like insert this line but it don't work:<xsl:for-each select="//products/product[substring-before(name,'(')=$category]">instead of<xsl:for-each select="//products/product[name=$category]">but it don't work.Andreawith your code it work, but if I pass the variable display.asp?cat=Corso%20MS%20Accessit dont work.Andrea Link to comment Share on other sites More sharing options...
aalbetski Posted November 7, 2007 Share Posted November 7, 2007 You are passing an argument on the querystring, but you need to pass that value to the XSLT. Show the code from the ASP page that does that job Link to comment Share on other sites More sharing options...
boen_robot Posted November 7, 2007 Share Posted November 7, 2007 with your code it work, but if I pass the variable display.asp?cat=Corso%20MS%20Accessit dont work.AndreaLet me paraprase what aalbetski said - show the ASP code, or at least the part that initiates the XSLT transformation. You may not be passing the parameter. After all, passing is not done automatically, and we should verify that you have the code to do the passing. Link to comment Share on other sites More sharing options...
andreathedove Posted November 7, 2007 Author Share Posted November 7, 2007 with your code it work, but if I pass the variable display.asp?cat=Corso%20MS%20Accessit dont work.AndreaThanks, it work. Link to comment Share on other sites More sharing options...
aalbetski Posted November 7, 2007 Share Posted November 7, 2007 This is a complete ASP page passes a parameter from the query string to the XSLT. Note the use of the decodeURI function. This is critical to remove encoding from the query string item. <%@ language=javascript %><% var arg = decodeURI(Request.QueryString("cat")) var xmlSource = new ActiveXObject("Msxml2.DOMDocument.4.0") var xslStyle = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0") xmlSource.async = false xslStyle.async = false xmlSource.load(Server.MapPath("products.xml")) xslStyle.load(Server.MapPath("products.xsl")) xslStyle.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'") var objTransformer = new ActiveXObject("Msxml2.XSLTemplate.4.0") objTransformer.stylesheet = xslStyle.documentElement var objProcessor = objTransformer.createProcessor() objProcessor.input = xmlSource objProcessor.addParameter("category",arg,"") objProcessor.transform() Response.Write(objProcessor.output)%> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.