[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSL java extension newbie question

Subject: XSL java extension newbie question
From: "sivaram g" <raviyellanet@xxxxxxxxxxx>
Date: Thu, 02 Oct 2003 19:38:33 +0000
xsl java
Hi,

I am trying to write a simple test xsl file using java extensions. I have a simple xml file that says

<items>
  <item>
     <name>a</name>
  </item>
  <item>
     <name>b</name>
  </item>
</item>

I want to use xsl to gather all the item names into a class called MyTest

so i have MyTest.java as

public class MyTest
{
  int itemsCount=0;
  public void foundItem()
  {
     itemsCount++;
  }
}

I want to create an object of this class and pass to an xsl stylesheet so it can update it when the transformation is being done. And I cant find a way to get the stylesheet to access the object i have passed in. it seems to create a new object of type MyTest and update it. A lot of examples i've seen of passing objects as parameters into XSLs only seem to print it out in the xsl...how do i update the passed in parameter in the xsl.

my main reads...
public static void main (String[]args)
 {
   String xmlFile = "input.xml";
   String xslFile = "input.xsl";
   MyTransformer myt;
   Source xml;
   Source xsl;
   Result result = new StreamResult (System.out);
   HashMap params = new HashMap ();

MyTest x=new MyTest();

   try
   {
     myt = new MyTransformer ();
     xml = myt.SourceFromFilename (xmlFile);
     xsl = myt.SourceFromFilename (xslFile);
     params.put ("changeme", x);
     myt.transform (xml, xsl, result, params);
     System.out.println("%%%%%%%%%%%\n"+x.itemsCount);
   } catch (Exception e)
   {
     System.out.println ("Exception: " + e.getMessage ());
   }

and the xsl reads as
<?xml version="1.0"  ?>

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:xalan="http://xml.apache.org/xalan"
 xmlns:mytest="MyTest"
 extension-element-prefixes="mytest">
 <xsl:param name="changeme" />
 <xsl:template match="/">
       <!-- this does print the object as in main -->
       <xsl:value-of select="$changeme"/>
       <xsl:apply-templates select="items">
         <xsl:with-param name="changeme"  select="$changeme" />
       </xsl:apply-templates>
 </xsl:template>
 <xsl:template match="items">
     <xsl:apply-templates select="item">
     </xsl:apply-templates>
 </xsl:template>
 <xsl:template match="item">
     <xsl:value-of select="mytest:foundItem()"/>
 </xsl:template>

</xsl:stylesheet>


please point to a doc/example which shows how to use the object passed into the xsl.


thanks
sivaram

_________________________________________________________________
Share your photos without swamping your Inbox. Get Hotmail Extra Storage today! http://join.msn.com/?PAGE=features/es



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.