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

Problems with resolving URIs in under Java JDK 1.4 Bet

Subject: Problems with resolving URIs in under Java JDK 1.4 Beta 3
From: "Ahmed Sako" <asako@xxxxxxxxxx>
Date: Tue, 18 Dec 2001 18:26:59 -0500
ahmed sako
I have written a set of templates, that work when invoked directly using
an xslt processor (I used both Saxon and MSXML 3.0 SP1 while I was
creating the templates).

The templates output their results directly to output files (using
xsl:document) and tend to have the following form:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output omit-xml-declaration="yes" method="text"/>

<xsl:param name="xmlDirName"
select="'file:///C:/Projects/linx/xTrade/src/com/linx/xtrade/messaging/g
enerator/xmlmessagedefinition/_testData'"/>
<xsl:param name="outputDirName"
select="'C:/Projects/linx/xTrade/src/com/linx/xtrade/messaging/generator
/xmlmessagedefinition/_testData/tmp'"/>
<xsl:param name="fileDelimiter" select="&#39;/&#39;" />

<xsl:variable name="fixTagXmlFile" select="concat($xmlDirName,
'/fixtagsdef.xml')"/>
<xsl:variable name="simpleDataTypeXmlFile" select="concat($xmlDirName,
'/valuesdef.xml')"/>
<xsl:variable name="complextDataTypeXmlFile" select="concat($xmlDirName,
'/fixfieldgroupsdef.xml')"/>

<xsl:variable name="messageListXmlFile" select="concat($xmlDirName,
'/fixmessagedef.xml')"/>
<xsl:variable name="messageDefinitionXmlDir" select="concat($xmlDirName,
'/fixmessages')"/>

<xsl:variable name="allFixTagNodes" select="document ($fixTagXmlFile)"/>
<xsl:variable name="allsimpleDataTypeNodes" select="document
($simpleDataTypeXmlFile)"/>
<xsl:variable name="allComplexDataTypeNodes" select="document
($complextDataTypeXmlFile)"/>


	<xsl:template match="/">
		<xsl:apply-templates/>
	</xsl:template>

	<xsl:template match="blah1">
		<xsl:apply-templates/>
	</xsl:template>

	<xsl:template match="blah2">


<xsl:variable name="currentComponentBlockNode" select="."/>
<xsl:variable name="currentComponentBlockName"
select="string($currentComponentBlockNode/@name)"/>
<xsl:variable name="regularFieldNodes"
select="$allFixTagNodes/fixtagsdef/fixtag[@id =
$currentComponentBlockNode/fixfields/fixfield/@ref]"/>
<xsl:variable name="allComplexFieldNodes"
select="$currentComponentBlockNode/fixfields/fixfieldgroup"/>
<xsl:variable name="componentBlockFieldNodes"
select="$allComplexFieldNodes[not(contains(@ref, 'Group'))]"/>
<xsl:variable name="repeatingGroupFieldNodes"
select="$allComplexFieldNodes[contains(@ref, 'Group')]"/>

<xsl:variable name="currentFileName" select="concat ($outputDirName,
concat($fileDelimiter, concat($currentComponentBlockName,
&#39;.java&#39;)))" />
<xsl:document href="{$currentFileName}">

.
.
.
. Do some more xslt work
.
.
.
.

</xsl:document>
</xsl:if>

		<xsl:apply-templates/>
	</xsl:template>

	<xsl:include href="toConstantName.xsl" />
	<xsl:include href="toObjectName.xsl" />
	<xsl:include href="mapFixFieldTypeToInternalType.xsl" />
	<xsl:include href="mapFixFieldTypeToEnumType.xsl" />
	<xsl:include href="getFieldNameFromTagNum.xsl" />

</xsl:stylesheet>

To automate the transformation process, I decided to use the TraX api in
Java JDK 1.4 Beta 3. I notices that I was to successfully excute the
templates if I removed the includes and replaced them with the in-line
code.

With the includes I was initially getting the following Error:

javax.xml.transform.TransformerConfigurationException:
javax.xml.transform.TransformerException:
javax.xml.transform.TransformerException: Had IO Exception with
stylesheet file: toConstantName.xsl

I didn't think that I needed to provide a custom URIResolver as all the
paths are relative, so I tried setting a systemID for the source items.
When I do this, I get the following error, which makes no sense to me:

javax.xml.transform.TransformerException:
javax.xml.transform.TransformerException:
org.apache.xml.utils.URI$MalformedURIException: The scheme is not
conformant.

The java code looks like this:

Where 

- xmlFileName = "c:/test/file.xml"
- xslFileName = "c:/test/firstStage.xsl"
- outputDir = "c:/tmp"

---

	void generate (String xmlFileName, String xslFileName, String
outputDir)
	{


	  try
	  {
		String xmlSystemId = new
File("c:/test").toURL().toExternalForm( );
		String xsltSystemId = new
File("c:/xsl").toURL().toExternalForm( );


		// create the transformerfactory & transformer instance
		TransformerFactory tf =
SAXTransformerFactory.newInstance();

		// process the XSLT stylesheets into a Templates
instance
		// with our TransformerFactory instance

		Source xslSource = new StreamSource(new
FileInputStream(xslFileName));
		xslSource.setSystemId(xsltSystemId);
		Templates mappingTemplate = tf.newTemplates(xslSource);

		Transformer mappingTransFormer    =
mappingTemplate.newTransformer();;
		Result transJavaGenerationResult       = null;
		Source xmlSource                      = null;
		StreamSource xmlJavaGenerationSource  = null;

		ByteArrayOutputStream xmlByteArrayOutputStream = new
ByteArrayOutputStream();

		xmlSource = new StreamSource(new
FileInputStream(xmlFileName));
//		xmlSource.setSystemId(xmlSystemId);
		// create the result target of the transformation can be
a DOM node, SAX stream,
		// or a java out stream/reader

		// We dump the output of the aggregation transformation
into a ByteArrayOutputStream
		transJavaGenerationResult = new
StreamResult(xmlByteArrayOutputStream);

		// now we set the input parameters for the style sheets
		mappingTransFormer.setParameter("xmlDirName", "\'" +
xmlSystemId + "\'");
//		mappingTransFormer.setParameter("outputDirName", "\'" +
outputDir + "\'");
		mappingTransFormer.setParameter("outputDirName", "\'" +
new File(outputDir).toURL().toExternalForm( ) + "\'");
//		mappingTransFormer.setParameter("fileDelimiter", "\'" +
FileAccess.FILE_PATH_ELEMENT_SEPARATOR + "\'");
		mappingTransFormer.setParameter("fileDelimiter",
"\'\'");

		// execute transformation & fill result target object.
The the java files are written
		// directly to the file system, by the xslt processor
		mappingTransFormer.transform(xmlSource,
transJavaGenerationResult);

		System.out.println("+++ Generated the java file for: " +
xmlFileName  + "+++++" );
	
System.out.println("====================================================
==============\n\n " );

		// Clear out tmp stuff
		mappingTemplate = null;
		transJavaGenerationResult = null;
		xmlSource = null;
		xmlByteArrayOutputStream.reset();
	  }
	  catch (Exception ex)
	  {
		System.out.println("\n\n\n !!!!!!!! generateMessages
failed because of: " + ex + " !!!!!!!!\n\n\n ");
		System.exit(-20);
	  }
	}
----

Any help would be greatly apreaciated...

rgds.as
___________________________________________________________________ 
Ahmed Sako                                  asako@xxxxxxxxxx
Linx, New York??                             
(212) 905-3079
___________________________________________________________________
"The beauty remains; the pain passes" - Pierre-Auguste Renoir 
 




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


Current Thread
  • wrap text
    • ajay sinha - Mon, 17 Dec 2001 14:44:07 -0500 (EST)
      • Michael Kay - Mon, 17 Dec 2001 15:30:59 -0500 (EST)
        • Ahmed Sako - Tue, 18 Dec 2001 18:28:44 -0500 (EST) <=

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.