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 November 15th, 2007, 03:01 AM
Authorized User
 
Join Date: Nov 2007
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
 
Old November 15th, 2007, 05:05 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old November 15th, 2007, 05:14 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
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 -/
 
Old November 15th, 2007, 05:16 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
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 -/
 
Old November 15th, 2007, 05:57 AM
Authorized User
 
Join Date: Nov 2007
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes, perfect..!!

Thank you Mike and Sam!

vivek





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





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