Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    inside form element,form.submit in xsl not working

    <CODE>
    #print "<form action=main.cgi method=post name=formname>";
    #If I uncomment above line,form.submit in xsl file doesn't work
    my $parser = XML::LibXML->new();
    my $xslt = XML::LibXSLT->new();

    my $source = $parser->parse_file("abc.xml");
    my $style_doc = $parser->parse_file("abc.xsl");

    my $stylesheet = $xslt->parse_stylesheet($style_doc);

    my $results = $stylesheet->transform($source, args => "' '",val => "'2'");
    print $stylesheet->output_string($results);
    #print "</form>"
    </CODE>
    Above code otherwise works(form.submit in xsl works).But If I uncomment form lines above,then form.submit doesnt work.what can be the problem?
    <CODE>
    abc.xsl

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xslutput method="html"/>

    <xsl:template match="tracks">
    <form name="form1" method="POST" action="abc.cgi">
    <table border="1">
    <tr>
    <td> Parameter </td>
    <td> Description </td>
    <td> Value </td>
    </tr>
    <xsl:apply-templates/>
    </table>
    </form>
    <script>
    document.form1.submit();
    </script>
    </xsl:template>

    <xsl:template match="abc">
    <tr>
    <td>
    <xsl:value-of select="label"/>
    </td>
    <td>
    <xsl:value-of select="desc"/>
    </td>
    <td>
    <xsl:if test="label = 'machine name'">
    <input type="text" name="args1" value="">
    </input>
    </xsl:if>
    </td>
    </tr>
    </xsl:template>

    </CODE>

    <CODE>
    abc.xml

    <?xml version='1.0'?>
    <?xml-stylesheet href="abc.xsl" type="text/xsl"?>

    <tracks>
    <abc>
    <label>machine name</label>
    <desc>specify machine name</desc>
    </abc>
    </tracks>

    </CODE>

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by himanshu.2009 View Post
    Code:
    #print "<form action=main.cgi method=post name=formname>";
    #If I uncomment above line,form.submit in xsl file doesn't work
    my $parser = XML::LibXML->new();
    my $xslt = XML::LibXSLT->new();
    
    my $source = $parser->parse_file("abc.xml");
    my $style_doc = $parser->parse_file("abc.xsl");
    
    my $stylesheet = $xslt->parse_stylesheet($style_doc);
    
    my $results = $stylesheet->transform($source, args => "' '",val => "'2'");
    print $stylesheet->output_string($results);
    #print "</form>"
    Above code otherwise works(form.submit in xsl works).But If I uncomment form lines above,then form.submit doesnt work.what can be the problem?
    Code:
    abc.xsl
    
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xslutput method="html"/>
    
    <xsl:template match="tracks">
    <form name="form1" method="POST" action="abc.cgi">
    <table border="1">
    <tr>
    <td> Parameter </td>
    <td> Description </td>
    <td> Value </td>
    </tr>
    <xsl:apply-templates/>
    </table>
    </form>
    <script>
    document.form1.submit();
    </script>
    </xsl:template>
    
    <xsl:template match="abc">
    <tr>
    <td>
    <xsl:value-of select="label"/>
    </td>
    <td>
    <xsl:value-of select="desc"/>
    </td>
    <td>
    <xsl:if test="label = 'machine name'">
    <input type="text" name="args1" value="">
    </input>
    </xsl:if>
    </td>
    </tr>
    </xsl:template>
    
    </CODE>
    
    <CODE>
    abc.xml
    
    <?xml version='1.0'?>
    <?xml-stylesheet href="abc.xsl" type="text/xsl"?>
    
    <tracks>
    <abc>
    <label>machine name</label>
    <desc>specify machine name</desc>
    </abc>
    </tracks>
    the forum code tags are [ code] and [ /code] not < code> and < /code>, you can edit your previous post to change that. Thank you.
    There are a couple of thing wrong here:
    - if you want to pass arguments to a stylesheet you must use something like that before xsl : output( in xslt stylesheet)
    Code:
    <xsl:param name="args" />
    <xsl:param name="val" />
    - the output result of transformation with xslt must be valid html, so I suggest to write a (x)html page with your output, validate and rebuild the xslt using that (x)html

    there are also some other things but are probably minor. For example you could pass arguments using a reference to a hash and format the parameters using xpath,
    see man page xml::libxslt section parameters, at the end of the manpage is a example.

    best regards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •