Jump to content

XML, XSLT and ASP


Recommended Posts

Hello,I am Andrea and this is my first post in this forum.My big problem is "HOW TO PASS parameters Using XSLT with ASP"The example: I have the stringcat2.asp?Cat=WebMasterthe code ASP for cat2.asp os

<%@ LANGUAGE = JScript %><%  // Set the source and style sheet locations here  var sourceFile = Server.MapPath("prova.xml");  var styleFile = Server.MapPath("categoria.xsl");    // Load the XML   var source = Server.CreateObject("Msxml2.DOMDocument");  source.async = false;  source.load(sourceFile);  // Load the XSL  var style = Server.CreateObject("Msxml2.DOMDocument");  style.async = false;  style.load(styleFile);var objStylesheetParam   =style.addParameter; "mastercategory", Request.QueryString("Cat")    // Repeat the above for as many xsl:param-s as necessarysource.transformNodeToObject(style, Response);%>

my XML to Trasform ishttp://www.allinonenet.it/esempi/prova.xmlans Finaly my XSLT is

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"><xsl:param name="mastercategory"/>  <table>   <xsl:for-each select="/NewDataSet/Table[MasterCategoria=@mastercategory][not(Categoria = preceding-sibling::Table/Categoria)]">    <xsl:sort select="Categoria" data-type="text" order="ascending"/>    <tr>     <td>      <a href="lista.asp?cid={Categoria}" title="Previous"><xsl:value-of select="Categoria"/></a> </td>     <td>     </td>    </tr>   </xsl:for-each>  </table> </xsl:template></xsl:stylesheet>

My bad result ishttp://www.allinonenet.it/esempi/cat2.asp?Cat=PS%20ONEWhy don't work the code ?I please you to help me, thanksAndrea

Link to post
Share on other sites

It may be because you have two predicates in this expression:

/NewDataSet/Table[MasterCategoria=@mastercategory][not(Categoria = preceding-sibling::Table/Categoria)]

And as far as I know, only one predicate is allowed per level. If you need to define two or more criterias, use "and" instead like this:

/NewDataSet/Table[MasterCategoria=@mastercategory and not(Categoria = preceding-sibling::Table/Categoria)]

Link to post
Share on other sites

Hmm... you may need to enclose the values from the right as strings, like this:

/NewDataSet/Table[MasterCategoria=string(@mastercategory) and not(Categoria = string(preceding-sibling::Table/Categoria))]

I'm not exactly sure how to use the not() function, but unless it's critical for the output, you may try this:

/NewDataSet/Table[MasterCategoria=string(@mastercategory) and Categoria != string(preceding-sibling::Table/Categoria)]

Link to post
Share on other sites

... in this mode the code work

<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:output method="html" version="4.0" /> <xsl:param name="mastercategoria"/><xsl:template match="/"><HTML><BODY><h2>Messages for General Group</h2><xsl:apply-templates select="/NewDataSet/Table[MasterCategoria=$mastercategoria and not(Categoria = preceding-sibling::Table/Categoria)]/Categoria" /></BODY></HTML></xsl:template><xsl:template match="Categoria" mode="toc"><DIV STYLE="margin-left:2em"><br></br><xsl:element name="a"><xsl:attribute name="href">viewmessage.asp?id=<xsl:value-of select="@Categoria"/></xsl:attribute><xsl:value-of select="@Categoria"/></xsl:element><br></br><xsl:apply-templates select="Categoria" mode="toc"/></DIV></xsl:template></xsl:stylesheet>

but the problem is display link".http://www.allinonenet.it/esempi/cat2.asp?Cat=PS ONE:-(Andrea

Link to post
Share on other sites

Are you sure everything is OK with your stylesheet? When I open the link you gave I see the following error:

msxml3.dll error '80004005'The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document./esempi/cat2.asp, line 26
And after some "investigation" I found the actual source of your XSLT:
<?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:variable name="mastercategoria"/> <html><body></body></html></xsl:variable><xsl:template match="/"><xsl:param name="mastercategoria" /><xsl:for-each select="/NewDataSet/Table/Categoria"/>(<xsl:value-of select="$Categoria"/>)</xsl:for-each></xsl:template></xsl:stylesheet>

Where the error is pretty obvious. You have an empty variable called "mastercategoria" and at the same time, a closing variable tag, without opening one. Try to alter the code in your post instead of this one.

Link to post
Share on other sites

Hello,the code works:

<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:output method="html" version="4.0"/><xsl:param name="mastercategoria"/> <xsl:template match="/">	<HTML>  <BODY> 	 <h2>Messages for General Group</h2> 	 <xsl:apply-templates select="NewDataSet/Table[MasterCategoria=$mastercategoria and not(Categoria = preceding-sibling::Table/Categoria)]" mode="toc" />  </BODY>	</HTML></xsl:template>	<xsl:template match="Table" mode="toc">	  <DIV STYLE="margin-left:2em">	<br></br>            <xsl:element name="a">    <xsl:attribute name="href">    viewmessage.asp?id=<xsl:value-of select="Categoria"/>	</xsl:attribute>	<xsl:value-of select="Categoria"/>	</xsl:element>	<table><tr><td colspan="2" width="130" bgcolor="#fff3ff" align="center">                           <xsl:value-of select="Categoria"/>                     </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>                </tr>    </table> <xsl:apply-templates select="Table"  mode="toc"/>		</DIV></xsl:template>  </xsl:stylesheet>

Andrea :):):)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...