[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Passing Parameters from java to XSL


Subject: [xsl] Passing Parameters from java to XSL
From: Margarita Manterola <margaritam@xxxxxxxxxx>
Date: 07 Nov 2002 11:32:06 -0300

I've been browsing the archives and I've found that this is a common
problem, but most people just want to pass one string parameter.  In my
case, I want to pass a NodeSet.

I'm using saxon as the parser, and J2EE 1.3.1.

The code I'm using is quite complex, so I'm going to include the most
significant snippets.

Mainly the idea is to include a special xml as a parameter to many other
xmls.

=== XMLConverter.java ===
public class XMLConverter 
{
...
 public void xml2file(String strXSLURL, Node oRelationshipsNode,
                      Node oXMLNode, String strFile)
   throws TransformerException, TransformerConfigurationException, 
   FileNotFoundException, IOException
 {

     StreamSource oXSLSource = new StreamSource(strXSLURL);
     DOMSource oXMLSource = new DOMSource(oXMLNode);
     FileOutputStream oFileOutput = new FileOutputStream(strFile);

     TransformerFactory oFactory = TransformerFactory.newInstance();
     Transformer oTransformer = oFactory.newTransformer(oXSLSource);
     oTransformer.setParameter("relationships", oRelationshipsNode);

     oTransformer.transform(oXMLSource, new StreamResult(oFileOutput));
  }


=======================

=== xml2java.jsp ===

 // This gets a node inside the XML, using a custom XPath reader
 XPathReader oRelReader = new XPathReader(strRelationshipsURL);
 Node oRelNode = oRelReader.getNode("/ecrm/relationships");

 XPathReader oReader = new XPathReader(xmlURL);
 NodeIterator iterator;
 Node node;
 iterator = oReader.getNodeIterator("/ecrm/entity");
 while ((node = iterator.nextNode()) != null)
 {
   String file = oReader.getXPathString(node, "@name") + ".java";
   String path = "/home/margaritam/";
   converter.xml2file(xslURL, oRelNode, node, path + file);
 }	
====================

=== relationships.xml ===
<?xml version='1.0' encoding='ISO-8859-1'?>
<ecrm>
   <relationships>
      <relationship object="Contact" field="account"
        related_object="Account" />
      ...
   </relationships>
</ecrm>
========================

=== accounts.xml ===

<ecrm>
  <entity package="com.coremation.ecrm" name="Account" > 

  ...

  </entity>
</ecrm>

====================

==== entity_bean.xsl ====

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:param name="relationships" /> 
<xsl:output method="text" />
<xsl:include href="general.xsl" />

<xsl:template match="/">
<xsl:param name="relationships" /> 
<xsl:apply-templates select="ecrm/entity" >
	<xsl:with-param name="relationships" /> 
</xsl:apply-templates>
</xsl:template>

<xsl:template match="entity">
<xsl:param name="relationships" /> 
   ....
</xsl:param>
</xsl:template>
</xsl:stylesheet>
=========================

If I include only the first <xsl:param name="relationships" />  (the one
outside everything), nothing happens, and the same when I include the
first and the second.  But when I include the one inside the
<xsl:template match="entity"> I get an ArrayOutOfBoundsException.

PLEASE! Help me!

Regards,
Margarita.




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



Current Thread
Keywords