Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Mon, 21 Apr 2008 07:51:54 -0700 (PDT),    group: microsoft.public.xsl        back       


XSL and Global Parameters   
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?
date: Mon, 21 Apr 2008 07:51:54 -0700 (PDT)   author:   Danjojo

Re: XSL and Global Parameters   
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/
date: Mon, 21 Apr 2008 17:04:33 +0200   author:   Martin Honnen

Re: XSL and Global Parameters   
> 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
...
date: Mon, 21 Apr 2008 08:30:22 -0700 (PDT)   author:   Danjojo

Re: XSL and Global Parameters   
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/
date: Mon, 21 Apr 2008 18:06:45 +0200   author:   Martin Honnen

Re: XSL and Global Parameters   
> 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.
date: Mon, 21 Apr 2008 10:29:39 -0700 (PDT)   author:   Danjojo

Re: XSL and Global Parameters   
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>
date: Mon, 21 Apr 2008 11:58:10 -0700 (PDT)   author:   Danjojo

Re: XSL and Global Parameters   
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/
date: Tue, 22 Apr 2008 13:26:29 +0200   author:   Martin Honnen

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us