I am using XSLT 1.0 and MSXML 4.0 for processing. =20 I have a snippet of XML that looks like: <?xml version=3D"1.0" encoding=3D"iso-8859-1"?> <menu id=3D"menuData"> <!--™ trademark--> <!--® registered--> <category name=3D"c1_products" display_name=3D"Category = One"> <info> <keyword>C1</keyword> <link>/category/c1_products</link> <titletag>C1 Products from our store - 9 Words for best SEO</titletag> <images> <image/> </images> </info> <category name=3D"c1_sub1_products" display_name=3D"sub-Category c1_sub1"> <info> <keyword>C1SUB1</keyword> <link>/products/c1_products/c1_sub1_products</link> <titletag>C1SUB1 Products from our store - 9 Words for best SEO</titletag> <images> <image>/imagesEdp/default_sm.jpg</image> </images> </info> </category> </category> </menu> Using ASP I have passed a global parameter to the XSL template. But I am having no luck pulling/using the parameter. I am passing c1_products. And I want the XSL to basicly return the data from the child node-set. How do I do this in XSL?
Danjojo wrote: > Using ASP I have passed a global parameter to the XSL template. > > But I am having no luck pulling/using the parameter. > > I am passing c1_products. And I want the XSL to basicly return the > data from the child node-set. > > How do I do this in XSL? I don't understand what you want to achieve. If you want to declare a global parameter in your XSLT then you do it like this: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:param name="p1"/> </xsl:stylesheet> then you set it using the MSXML API doing xsltProcessor.addParameter("p1", "c1_products"); which passes a string value "c1_products" as the parameter value. You could use that parameter in your stylesheet e.g. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:param name="p1"/> <xsl:template match="/"> <xsl:apply-templates select="menu/category[@name = $p1]"/> </xsl:template> <xsl:template match="category"> ... </xsl:template> </xsl:stylesheet> -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
> I don't understand what you want to achieve. > If you want to declare a global parameter in your XSLT then you do it > like this: > > <xsl:stylesheet > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="1.0"> > > <xsl:param name="p1"/> > > </xsl:stylesheet> > > then you set it using the MSXML API doing > xsltProcessor.addParameter("p1", "c1_products"); > which passes a string value "c1_products" as the parameter value. > > You could use that parameter in your stylesheet e.g. > > <xsl:stylesheet > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="1.0"> > > <xsl:param name="p1"/> > > <xsl:template match="/"> > <xsl:apply-templates select="menu/category[@name = $p1]"/> > </xsl:template> > > <xsl:template match="category"> > ... > </xsl:template> > > </xsl:stylesheet> > I definately get that, although I don't understand why I get 0 results. Here is what I have, just like you have shown. <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/ Transform"> <xsl:output method="html" indent="yes"/> <xsl:param name="paraCatagory"/> <xsl:template match="/"> <xsl:apply-templates select="menu/category[@name = $paraCatagory]"/ > <xsl:apply-templates/> </xsl:template> <xsl:template match="category"> <xsl:text>test</xsl:text> </xsl:template> </xsl:stylesheet> I am passing from ASP just as described as well. ... ' add parameters to the xsl Set XSLTemplate = Server.CreateObject("MSXML2.XSLTemplate") Set XSLTemplate.stylesheet = objXSL Set procXML = XSLTemplate.createProcessor() ' set the source of the data procXML.input = objCatXML procXML.addParameter "paraCatagory", cstr(strMenuName) procXML.Transform Response.Write procXML.output ...
Danjojo wrote: > I definately get that, although I don't understand why I get 0 > results. > > Here is what I have, just like you have shown. > > <?xml version="1.0" encoding="ISO-8859-1"?> > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/ > Transform"> > <xsl:output method="html" indent="yes"/> > <xsl:param name="paraCatagory"/> > > <xsl:template match="/"> > <xsl:apply-templates select="menu/category[@name = $paraCatagory]"/ > <xsl:apply-templates/> > </xsl:template> > <xsl:template match="category"> > <xsl:text>test</xsl:text> > </xsl:template> > </xsl:stylesheet> > > I am passing from ASP just as described as well. > > ... > ' add parameters to the xsl > Set XSLTemplate = > Server.CreateObject("MSXML2.XSLTemplate") You earlier said you are using MSXML 4 but to do that you need Server.CreateObject("MSXML2.XSLTemplate.4.0") although that should not be the problem. I am not sure where the problem is, try to debug that with outputting e.g. <xsl:value-of select="concat('Parameter is: ', $paraCatagory)"/> and e.g. <xsl:value-of select="concat('Found ', count(menu/category[@name = $paraCatagory]), ' categories.')"/> -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
> You earlier said you are using MSXML 4 but to do that you need > Server.CreateObject("MSXML2.XSLTemplate.4.0") > although that should not be the problem. > I am not sure where the problem is, try to debug that with outputting e.g. > <xsl:value-of select="concat('Parameter is: ', $paraCatagory)"/> > and e.g. > <xsl:value-of select="concat('Found ', count(menu/category[@name = > $paraCatagory]), ' categories.')"/> > > -- > > Martin Honnen --- MVP XML > http://JavaScript.FAQTs.com/ Well I am getting results of "some kind" now... Parameter Passed is: c1_products Found 0 categories. Found 0 categories. Found 0 categories. Found 0 categories. Found 0 categories. Found 0 categories. In my debug browser. It is still not matching, but thank you for helping me "prove" the variable is indeed passed.
I figure I better keep the same thread although it is now a different problem. How do I match on my parameter if it does not like Parameters in the xpath match attribute? What I have will not work.. what will please? <xsl:template match="/"> <xsl:element name="span"> <xsl:attribute name="style">color: red</xsl:attribute> <xsl:value-of select="concat('Parameter Passed is: ', $paraCatagory)"/> </xsl:element> <br/> <xsl:apply-templates select="menu"/> </xsl:template> <xsl:template match="menu/category[@name = $paraCatagory]"> <xsl:value-of select="." /><br/> </xsl:template>
Danjojo wrote: > I figure I better keep the same thread although it is now a different > problem. > > How do I match on my parameter if it does not like Parameters in the > xpath match attribute? > What I have will not work.. what will please? > > <xsl:template match="/"> > <xsl:element name="span"> > <xsl:attribute name="style">color: red</xsl:attribute> > <xsl:value-of select="concat('Parameter Passed is: ', > $paraCatagory)"/> > </xsl:element> > <br/> > <xsl:apply-templates select="menu"/> > </xsl:template> > > <xsl:template match="menu/category[@name = $paraCatagory]"> > <xsl:value-of select="." /><br/> > </xsl:template> XSLT 2.0 allows you to use parameters/variables in match patterns so that could be a reason to move on to XSLT 2.0. It is currently supported by three processors, Saxon comes in a Java and in a .NET version (http://saxon.sourceforge.net/), AltovaXML (http://www.altova.com/altovaxml.html) is a COM implementation that can be used with .NET and Java too and Gestalt is an Eiffel implementation (http://gestalt.sourceforge.net/). If you want to continue to use your XSLT 1.0 processor then you need to move the test into the template e.g. <xsl:template match="menu/category[@name]"> <xsl:choose> <xsl:when test="@name = $paraCategory"> ... </xsl:when> <xsl:otherwise> ... </xsl:otherwise </xsl:choose> </xsl:template> -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/