Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 7th, 2004, 02:12 PM
Registered User
 
Join Date: Sep 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default parameterize path?

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>

</xsl:if>

</html>
</xsl:template>

</xsl:stylesheet>

 
Old October 7th, 2004, 03:06 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

So you replace:

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

with:

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

?
 
Old October 7th, 2004, 07:51 PM
Registered User
 
Join Date: Sep 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

 
Old October 8th, 2004, 12:06 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

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.

 
Old October 8th, 2004, 04:34 AM
Authorized User
 
Join Date: Jul 2004
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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>


         </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






Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help with path for loading Pics (app.path) Tabbasum Beginning VB 6 2 November 15th, 2007 04:57 AM
Implementing the all-path shortest path problem bitwords XSLT 1 December 6th, 2006 11:37 AM
using app.path in database path and filename kd8con VB Databases Basics 2 October 25th, 2006 11:45 AM
Convert logical path to absolute path zoostar J2EE 1 April 15th, 2005 10:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.