Subject: parameterize path?
Posted By: mlaba Post Date: 10/7/2004 2:12:05 PM
I want to be able to set my path as a parameter in my stylesheet. I would like to replace "TestResults/Limit" with my $path param but I can't get this thing to work to save my life!! Below is the XSL...can someone help me with this?

regards,

Mat

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:param name="path">TestResults/Limit</xsl:param>
<xsl:template match="/">
<html>

<xsl:if test="count(TestResults/Limits)&gt; 0">
      <table border="0" width="100%">
      <tr><b>Limits:</b></tr>
           
      <xsl:for-each select="TestResults/Limits/parameter">
    <tr>
<td>
<span style="font-weight:bold">
<xsl:value-of select="./@name" />:
</span>
<xsl:value-of select="." />       
      </td>
    </tr>       
      </xsl:for-each>
      </table>     
<hr/>
</xsl:if>

</html>
</xsl:template>

</xsl:stylesheet>

Reply By: bmains Reply Date: 10/7/2004 3:06:01 PM
So you replace:

<xsl:for-each select="TestResults/Limits/parameter">

with:

<xsl:for-each select="$path/parameter">

?
Reply By: mlaba Reply Date: 10/7/2004 7:51:06 PM
ya know...I never got that far! I have had all of the trouble with the syntax of the count() statement. As soon as I introduce the $path param into the count statement everything blows up...what would the correct syntax be for that?

Reply By: Santhi Reply Date: 10/8/2004 12:06:37 AM
Count() will expect NodeSet as an parameter and you are passing string value as param ,$path will return string.
and also i doubt <xsl:for-each select="$path/parameter">will work.

Reply By: barcher Reply Date: 10/8/2004 4:34:14 AM
Hi Mat,

You may be able to make use of an extension function, for example if using msxml processor:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:local="foobar">
   <xsl:param name="path">TestResults/Limit</xsl:param>

   <xsl:template match="/">
       
         <xsl:variable name="nodes" select="local:selectNodes(., string($path))" />
  
      <html>
         <xsl:if test="count($nodes)&gt; 0">
            <table border="0" width="100%">
               <tr>
                  <b>Limits:</b>
               </tr>

               <xsl:for-each select="$nodes">
                  <tr>
                     <td>
                        <span style="font-weight:bold">
                        <xsl:value-of select="./@name" />

                        :</span>

                        <xsl:value-of select="." />
                     </td>
                  </tr>
               </xsl:for-each>
            </table>

            <hr />
         </xsl:if>
      </html>
   </xsl:template>
   
    <msxsl:script implements-prefix="local" language="jscript">
    <![CDATA[
        function selectNodes(ctx, xPathExpr)
        {
            
            return ctx.nextNode().selectNodes(xPathExpr);
        }
    ]]>
    </msxsl:script>

   
</xsl:stylesheet>

Regards

Bryan


Go to topic 20342

Return to index page 750
Return to index page 749
Return to index page 748
Return to index page 747
Return to index page 746
Return to index page 745
Return to index page 744
Return to index page 743
Return to index page 742
Return to index page 741