DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Passing parameter to XSL through JSP!

  1. #1
    Kevin Holmes Guest

    Passing parameter to XSL through JSP!


    Hi,

    I am using Forte for Java, Community Edition 3.0 to develop a website. Is
    there a way to pass a parameter to an XSL stylesheet through JSP? There
    is a list of bios in an xml document, and I only want to bring up one at
    a time and don't want to create one xsl document per bio.

    Thanks!

    Kevin.



  2. #2
    Vijay Gummadi Guest

    Re: Passing parameter to XSL through JSP!


    Hi Kevin,

    Yes, it is possible to pass parameters to an XSL from JSPs/Servlets
    and then access the parameters from within the XSL. A XSL parser like Xalan
    supports parameters.

    In the JSP (using the Transformer of Xalan) , you can set a parameter using
    the following code:

    //Code follows
    import javax.xml.transform.*;
    import javax.xml.transform.stream.*;
    String xmlFile = "bio.xml";
    String xslFile = "bio.xsl";
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer(new StreamSource(xslFile));
    transformer.setParameter("bioName", "Kevin");
    transformer.transform(new StreamSource(xmlFile), new StreamResult(out));

    In the stylesheet, do the following:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xslaram name = "bioName" select = "$bioName"/>
    <xsl:template match="bio">
    <xsl:if test="contains(@id, $bioName)">
    <xsl:apply-templates select="WhatEver"/>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>

    Please customize the code above to suit your purposes. Good Luck.

    Vijay


    "Kevin Holmes" <kevin.holmes@thinkup.com> wrote:
    >
    >Hi,
    >
    >I am using Forte for Java, Community Edition 3.0 to develop a website.

    Is
    >there a way to pass a parameter to an XSL stylesheet through JSP? There
    >is a list of bios in an xml document, and I only want to bring up one at
    >a time and don't want to create one xsl document per bio.
    >
    >Thanks!
    >
    >Kevin.
    >
    >



  3. #3
    Ralph Hopkins Guest

    Re: Passing parameter to XSL through JSP!


    I ran this with Cooktop beta 2.200 April 2001 using XSLT engine MSXML.
    I added the <xslutput method ... as well as the last 4 missing lines.
    I don't know if this is what you intended and I don't know vml ... yet.
    Find and load Cooktop free from http://www.xmlcooktop.com


    <!-- <?xml version="1.0" encoding="BIG5"?> -->
    <xsl:stylesheet xmlns:xsl="http://www.w3org/tr/WD-xsl"
    xmlns:v="urn:schemas-microsoft-com:vml" >

    <xslutput method="html" media-type="image/vml" encoding="UTF-8" omit-xml-declaration="yes"/>

    <xsl:template match="/">

    <head>
    <style>
    v\:* { behavior: url(#default#VML); }
    </style>
    </head>
    <body>

    <xsl:for-each select="coordinate">
    <xsl:element name="v">
    <xsl:attribute name="style">
    width:50pt;height:50pt
    </xsl:attribute>
    <xsl:attribute name="fillcolor">
    blue
    </xsl:attribute>
    <xsl:attribute name="path">
    <xsl:value-of select="coordinate"/><br/>
    </xsl:attribute>
    </xsl:element>

    </xsl:for-each>
    </body>
    </xsl:template>
    </xsl:stylesheet>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center