Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 15th, 2007, 03:01 AM
Authorized User
 
Join Date: Nov 2007
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing Node as a Param from javascript to XSL

Hi,
     how to pass the node as a param from javascript to xslt?

for ex;
       javascript:
        function loadXml()
        {
         ....
         //node name as a parameter from javascript
         xslproc.addParameter("col1","Month");
        ........

        }

    Xslt:
        <?xml version="1.0"?>
        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:fx="#fx-functions" exclude-result-prefixes="msxsl fx">
            <xsl:output method="html" version="4.0" indent="yes" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>


          <xsl:param name="col1"/>

          <xsl:template match="dataroot" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                  <xsl:for-each select="Inventry">
                      <xsl:value-of select="$col1"/>
                  </xsl:for-each>
            </xsl:template>
        </xsl:stylesheet>

    I want "$col1" must act as like below;

    ...........
          <xsl:value-of select="Month"/>
    .........

    Of course, value-of select returns string of $col1 as "Month". How can I convert "Month" string as a Node Name?
Pls help me...!

Thanks in Advance


vivek
__________________
vivek
Reply With Quote
  #2 (permalink)  
Old November 15th, 2007, 05:05 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It looks to me as if you are not trying to pass a node from the Javascript to the XSLT, rather you are trying to pass a string that contains the name of a node.

If $col1 is the name of an element then you can select the corresponding elements using something like

select="*[local-name()=$col1]"

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old November 15th, 2007, 05:14 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You can't do it the way you are trying to do it. You'd have to include a msxml:script element in your stylesheet to parse the string I think, something like this:

<msxsl:script language="JScript" implements-prefix="mylib">
    function getNode(root, string) {
      return root.selectSingleNode(string);
    }
</msxsl:script>

(disclaimer: I haven't tested this function, so it might not work, but hopefully it will set you off in the right direction).

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #4 (permalink)  
Old November 15th, 2007, 05:16 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

(or use Michael's solution, which is probably easier, doh!)

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #5 (permalink)  
Old November 15th, 2007, 05:57 AM
Authorized User
 
Join Date: Nov 2007
Location: , , .
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes, perfect..!!

Thank you Mike and Sam!

vivek
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
passing javascript variable in xsl:value-of select eruditionist XSLT 2 September 19th, 2008 05:23 PM
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
xsl:variable holding name of an xsl:param perissos XSLT 0 December 5th, 2006 07:09 AM
Problems passing xsl parameters from javascript mxxz XSLT 4 November 3rd, 2006 11:21 AM
The difference between xsl:variable and xsl:param NEO1976 XML 2 July 24th, 2006 06:05 AM



All times are GMT -4. The time now is 07:27 AM.


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