473,748 Members | 7,217 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help! 'dummy.xsl' ?

As various people will have noticed, I've been having a lot of trouble with
XSL lately. Brief history: I wrote myself an XML toolkit back in 2000, and
it worked well enough for me, so it's been little changed since. However,
it works only with an obsolete version of Saxon (6.2.2 I think), and it
has a number of small bugs; and I've at last got to the point where I need
to fix it. And I'm finding it, frankly, absurdly frustrating and
difficult.

But what's frustrating me at this moment is something absurd and weird.
Some weeks ago I did a test with a dummy XSL file called 'dummy.xsl'. Now,
whenever I test with modern Xalan2, I'm persistently getting an error
message:

/home/simon/tmp/test/dummy.xsl; Line #0; Column #0; stylesheet requires
attribute: version

I am really, really not referring to a file called 'dummy.xsl'. I have
grepped through every single file in my working set, and nothing - really
nothing at all - contains the text 'dummy.xsl'. Also, the stylesheet I am
using, really does have a version attribute - see below.

I do not get this message when I'm using my obsolete version of Saxon (and,
indeed, all my transforms work with my obsolete Saxon). So I guessed that
Xalan might use a cache somewhere on my hard disk that I don't know about.
I copied my working files - all three of them, stripping my test down as
far as I could - to my laptop, which should be virgin.

When I run the test, on the laptop, using Xalan2, using GCJ as the Java
implementation I get the 'stylesheet requires attribute: version' error,
but no reference to dummy.xsl. But if I use IBM's Java, I get exactly the
same error message as I get on my development machine - *INCLUDING* the
reference to dummy.xsl!

So I now completely fail to understand where my problem is coming from. I
include my three files below, so that anyone who has the time and patience
can verify my problem and suggest solutions (hopefully not including
either pistols at dawn or a vial of cyanide)

,----[ /home/simon/tmp/xsltest/testharness.sh ]
#!/bin/bash

# XSLPROC=/usr/share/java/xalan2.jar
XSLPROC=/usr/local/lib/java/saxon.jar

export CLASSPATH=".:$X SLPROC"

javac TransformerTest Harness.java
java TransformerTest Harness \
-d org.apache.xerc es.dom.DOMImple mentationImpl -s test.xsl
`----

,----[ /home/simon/tmp/xsltest/test.xsl ]
<?xml version="1.0" encoding="UTF-8"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

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

<xsl:template match="@* node()">
<xsl:copy>
<xsl:apply-templates select="@* node()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
`----

,----[ /home/simon/tmp/xsltest/TransformerTest Harness.java ]
import org.apache.xml. serialize.Outpu tFormat;
import org.apache.xml. serialize.XMLSe rializer;

import org.w3c.dom.DOM Implementation;
import org.w3c.dom.Doc ument;
import org.w3c.dom.Ele ment;
import org.w3c.dom.Nod e;

import org.xml.sax.Inp utSource;

import java.io.File;
import java.io.FileInp utStream;
import java.io.FileOut putStream;
import java.io.OutputS tream;
import java.io.StringR eader;

import java.text.DateF ormat;

import java.util.Date;

import javax.xml.parse rs.DocumentBuil der;
import javax.xml.parse rs.DocumentBuil derFactory;
import javax.xml.trans form.Transforme rFactory;
import javax.xml.trans form.dom.DOMRes ult;
import javax.xml.trans form.dom.DOMSou rce;
import javax.xml.trans form.stream.Str eamResult;
/**
* Test XSL transformations
*/
public class TransformerTest Harness
{
//~ Static fields/initializers ------------------------------------------

/** A string with parsable content */
public static final String PARSETHIS =
"<parsable><p>P arse me</p></parsable>";

//~ Instance fields -----------------------------------------------------

/** the DOM Implementation I will use */
public DOMImplementati on rebus = null;

/** the XSL stylesheet (transform) I will use */
public File stylesheet;

/** DOCUMENT ME! */
public String label = "Transforme r test harness";

/**
* A directory into which to write output files - if null, use standard
* out
*/
protected File baseDir = null;

/** A factory class for XSL transformers; */
protected TransformerFact ory transformerFact ory = null;

//~ Constructors --------------------------------------------------------

/**
* Construct a new test harness
*/
public TransformerTest Harness( )
{
super( );

try
{
transformerFact ory = TransformerFact ory.newInstance ( );
}
catch ( Exception d )
{
System.err.prin tln( "Could not instantiate transformer: " +
d.getMessage( ) );
System.exit( 4 );
}
}

//~ Methods -------------------------------------------------------------

/**
* Generate a document
*
* @return the document
*/
public Document generate( )
{
Document doc = rebus.createDoc ument( "", "root", null );
Element root = doc.getDocument Element( );
Element generated = doc.createEleme nt( "generated" );
root.appendChil d( generated );

DateFormat df = DateFormat.getD ateTimeInstance ( );

generated.appen dChild( doc.createTextN ode( df.format( new
Date( ) ) ) );

try
{
root.appendChil d( maybeParse( doc, PARSETHIS ) );
}
catch ( Exception any )
{
System.err.prin tln( "Failed to parse: " + any.getMessage( ) );
}

return doc;
}

/**
* @param args
*/
public static void main( String[] args ) throws Exception
{
TransformerTest Harness tth = new TransformerTest Harness( );

for ( int i = 0; i < args.length; i++ )
{
if ( args[i].startsWith( "-" ) && ( args[i].length( ) 1 ) )
{
switch ( args[i].charAt( 1 ) )
{
case 'b':
tth.baseDir = new File( args[++i] );

if ( tth.baseDir.exi sts( ) &&
tth.baseDir.can Write( ) &&
tth.baseDir.isD irectory( ) )
{
System.err.prin tln( "Using base directory " +
tth.baseDir.get CanonicalPath( ) );
}
else
{
System.err.prin tln( "Bad base directory: " +
args[i] );
}

break;

case 'd':

try
{
tth.rebus =
(DOMImplementat ion) Class.forName( args[++i] )
.newInstance( );
System.err.prin tln(
"Using DOM implementation of class " +
tth.rebus.getCl ass( ).getName( ) );
}
catch ( Exception any )
{
System.err.prin tln( "Could not find DOM " +
"implementa tion " + args[i] );
System.err.prin tln( any.getMessage( ) );
System.exit( 2 );
}

break;

case 's':
tth.stylesheet = new File( args[++i] );

if ( tth.stylesheet. exists( ) &&
tth.stylesheet. canRead( ) )
{
System.err.prin tln( "Using XSL stylesheet " +
tth.stylesheet. getCanonicalPat h( ) );
}
else
{
System.err.prin tln( "Can't read stylesheet " +
args[i] );
System.exit( 1 );
}

break;

default:
System.err.prin tln( "Unrecognis ed arg " + args[i] );
System.exit( 3 );

break;
}
}
else
{
System.err.prin tln( "Unrecognis ed arg " + args[i] );
System.exit( 3 );

break;
}
}

tth.test( );
}

/**
* Get a suitable output stream - if I have a base directory, a file in
* that directory with this name; else the standard out
*
* @param name a name ofr my file if any
*
* @return an output stream
*
* @throws Exception unlikely
*/
public OutputStream getOutputStream ( String name )
throws Exception
{
OutputStream out = System.out;

if ( ( baseDir != null ) && baseDir.exists( ) &&
baseDir.canWrit e( ) && baseDir.isDirec tory( ) )
{
out = new FileOutputStrea m( new File( baseDir, name ) );
}

return out;
}
/**
* Run the tests
*/
public void test( )
{
Document generated = generate( );
System.out.prin tln( label );

try
{
System.out.prin tln( "Printer test -justprint" );
justPrint( generated, "justprint" );

if ( stylesheet != null )
{
DocumentBuilder p =
DocumentBuilder Factory.newInst ance( ).newDocumentBu ilder( );
Document xslDocument =
p.parse( new InputSource( new FileInputStream ( stylesheet ) ) );

System.out.prin tln( "Verify stylesheet -transform.xsl") ;
justPrint( xslDocument, "transform.xsl" );

System.out.prin tln( "DOM to DOM test -dom2dom" );
domToDom( generated, xslDocument, "dom2dom" );

System.out.prin tln( "DOM to Stream test -dom2stream" );
domToDom( generated, xslDocument, "dom2stream " );
}
else
{
System.err.prin tln( "No stylesheet?");
}
}
catch ( Exception e )
{
System.err.prin tln( "Whilst running print test:" );
e.printStackTra ce( );
}
}

/**
* Transform from DOM object to DOM object; seralize after
*
* @param doc the document transformed
* @param name the name for printing
*/
protected void domToDom( Document doc, Document xslDocument, String
name )
{
try
{
if ( stylesheet != null )
{
DOMSource domSource = new DOMSource( doc );
DOMResult domResult = new DOMResult( );

transformerFact ory.newTransfor mer( new DOMSource( xslDocument ) )
.transform( domSource, domResult );

Node root = domResult.getNo de( );

if ( root instanceof Document )
{
justPrint( (Document) root, name );
}
else
{
System.err.prin tln( "DOM to DOM transform returned " +
root );
}
}
}
catch ( Exception e )
{
System.err.prin tln( "DOM to DOM failed: " + e.getMessage( ) );
e.printStackTra ce( );
}
}

/**
* Transform from DOM object to output stream directly
*
* @param doc the document transformed
* @param transform the xsl transform to apply
* @param name the name for printing
*/
protected void domToStream( Document doc, Document transform, String
name )
{
try
{
if ( stylesheet != null )
{
DOMSource domSource = new DOMSource( doc );
StreamResult result =
new StreamResult( getOutputStream ( name ) );

transformerFact ory.newTransfor mer( new DOMSource( transform ) )
.transform( domSource, result );
}
}
catch ( Exception e )
{
System.err.prin tln( "DOM to DOM failed: " + e.getMessage( ) );
e.printStackTra ce( );
}
}

/**
* Just print the document
*
* @param doc the document to print
* @param name the name of the file to print to
*
* @throws Exception DOCUMENT ME!
*/
protected void justPrint( Document doc, String name )
throws Exception
{
XMLSerializer dickens =
new XMLSerializer( getOutputStream ( name ),
new OutputFormat( doc, null, true ) );
dickens.seriali ze( doc );
}

/**
* Construct a node representing this value. It's perfectly possible (and
* possibly legitimate) that the value of a child should contain embedded
* markup. If so, try to parse a node out of it.
*
* @param doc the document in which the node is to be created
* @param unparsed the string, possibly with embedded markup, to parse
*
* @exception GenerationExcep tion if parsing fails
*/
protected Node maybeParse( Document doc, String unparsed )
throws Exception
{
Node val = doc.createTextN ode( unparsed ); // safe default

if ( unparsed != null ) // defensive
{
if ( unparsed.indexO f( "<" ) -1 ) // it looks like markup
{
if ( !unparsed.trim( ).startsWith( "<" ) )
{
// nasty: if it contains markup, but
// isn't contained in markup, the
// parser will barf.
unparsed = "<parsed>" + unparsed + "</parsed>";
}

try
{
DocumentBuilder parser =
DocumentBuilder Factory.newInst ance( )
.newDocumentBui lder( );

if ( parser == null )
{
System.err.prin tln( "Could not initialise XML parser" );
}

InputSource i =
new InputSource( new StringReader( unparsed ) );

Document parsed = parser.parse( i );

if ( parsed != null )
{
Node root = parsed.getDocum entElement( );

val = doc.importNode( root, true );
}
}
catch ( Exception e )
{
System.err.prin tln( "Could not parse '" + unparsed +
"'as XML" );
e.printStackTra ce( System.err );
}
}
}

return val;
}
}
`----

,----[ Sample output with Saxon (i.e. what I think you should get) ]
Using DOM implementation of class
org.apache.xerc es.dom.DOMImple mentationImpl
Using XSL stylesheet /home/simon/tmp/xsltest/test.xsl
Transformer test harness
Printer test -justprint
<?xml version="1.0"?>
<root>
<generated>18-Mar-2007 14:33:26</generated>
<parsable>
<p>Parse me</p>
</parsable>
</root>
Verify stylesheet -transform.xsl
<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<test>
<xsl:apply-templates/>
</test>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
DOM to DOM test -dom2dom
<?xml version="1.0"?>
<test>
<root>
<generated>18-Mar-2007 14:33:26</generated>
<parsable>
<p>Parse me</p>
</parsable>
</root>
</test>
DOM to Stream test -dom2stream
<?xml version="1.0"?>
<test>
<root>
<generated>18-Mar-2007 14:33:26</generated>
<parsable>
<p>Parse me</p>
</parsable>
</root>
</test>

,----[ Sample output with Xalan2 ]
Using DOM implementation of class
org.apache.xerc es.dom.DOMImple mentationImpl
Using XSL stylesheet /home/simon/tmp/xsltest/test.xsl
Transformer test harness
Printer test -justprint
<?xml version="1.0"?>
<root>
<generated>18-Mar-2007 14:34:50</generated>
<parsable>
<p>Parse me</p>
</parsable>
</root>
Verify stylesheet -transform.xsl
<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<test>
<xsl:apply-templates/>
</test>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
DOM to DOM test -dom2dom
/home/simon/tmp/xsltest/dummy.xsl; Line #0; Column #0; stylesheet requires
attribute: version
file:///home/simon/tmp/xsltest/dummy.xsl; Line #0; Column #0;
java.util.Empty StackException
DOM to Stream test -dom2stream
/home/simon/tmp/xsltest/dummy.xsl; Line #0; Column #0; stylesheet requires
attribute: version
file:///home/simon/tmp/xsltest/dummy.xsl; Line #0; Column #0;
java.util.Empty StackException
--
si***@jasmine.o rg.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/

Do not sail on uphill water.
- Bill Lee

Mar 18 '07 #1
3 4240
Simon Brooke wrote:
DocumentBuilder p =
DocumentBuilder Factory.newInst ance( ).newDocumentBu ilder( );
I don't know whether that causes your problem but for namespace aware
processing
<http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/parsers/DocumentBuilder Factory.html#se tNamespaceAware (boolean)>
you should do e.g.
DocumentBuilder Factory docBuilderFacto ry =
DocumentBuilder Factory.newInst ance();
docBuilderFacto ry.setNamespace Aware(true);
DocumentBuilder p = docBuilderFacto ry.newDocumentB uilder();


--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 18 '07 #2
in message <45************ ***********@new sspool3.arcor-online.net>, Martin
Honnen ('m********@yah oo.de') wrote:
Simon Brooke wrote:
> DocumentBuilder p =
DocumentBuilder Factory.newInst ance( ).newDocumentBu ilder( );

I don't know whether that causes your problem but for namespace aware
processing
<http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/parsers/DocumentBuilder Factory.html#se tNamespaceAware (boolean)>
you should do e.g.
DocumentBuilder Factory docBuilderFacto ry =
DocumentBuilder Factory.newInst ance();
docBuilderFacto ry.setNamespace Aware(true);
DocumentBuilder p = docBuilderFacto ry.newDocumentB uilder();
Thank you very much indeed!

You may not know what my problem was, but you certainly managed to solve
it! What a /bizarre/ error message for that problem!

--
si***@jasmine.o rg.uk (Simon Brooke) http://www.jasmine.org.uk/~simon/

Due to financial constraints, the light at the end of the tunnel
has been switched off.

Mar 18 '07 #3
Simon Brooke wrote:
it! What a /bizarre/ error message for that problem!
not entirely bizarre, the top level element of an xsl stylesheet can be
any element in any namespace (because of the so called literal result
element as stylesheet syntax) however in that case there has to be an
xsl:version attribute on the LRE (basically so that a processor can trap
the case of a file which isn't an xsl file at all being passed in as xsl
code) so if there's an error in specifying the namespace, the
xsl:stylesheet is just some element in an unknown mamepsace, so the
system looks for an xsl:version attribute....
David
Mar 20 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
6553
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help Workshop program: hcw.exe that's included with Visual Basic. This exact same file compiled perfectly with no notes, warnings or errors prior to reformatting my system. Prior to the reformatting, I copied the help.rtf file onto a CD and checked the box to...
9
4411
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with the microsoft HTML workshop utility, lets call it c:\path\help.chm. My question is how do you launch it from the GUI? What logic do I put behind the "help" button, in other words. I thought it would be os.spawnv(os.P_DETACH,...
6
4346
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing result in any way. Who can help me, I thank you very very much. list.cpp(main program) //-------------------------------------------------------------------------- - #pragma hdrstop #pragma argsused
3
3362
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With numarray, help gives unhelpful responses:
7
5384
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available from clicking on many of the available topics (mostly methods but some properties are also unavailable). This same problem occurs with many, if not most, keywords. Is there any way I can activate these "missing" help topics? HELP!
5
3277
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time using "F1" help within the VB IDE. Is this expectation achievable In trying to test my help file in the IDE, I have a solution with 2 projects: the DLL and a tester. VB does not look for my help file; instead, it looks for path to my source code...
8
3233
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both including search the internet for help, but the help is worthless. Any ideas?
10
3364
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably the worst I ever seen. I almost cannot find anything I need, including things I
1
6135
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve default property of object Label. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"' Label = New Object(){Box1, Box2, Box3, Box4, Box5, Box6, Box7, Box8, Box9, Box10, Box11,...
0
2887
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application calls MS Excel, so the scenario is that I am supposed to see the Excel Menu bar, FILE EDIT VIEW INSERT ... HELP. I am able to see the menu bar, but in case of Help, I see the Help of Excel and help of my application, both as a submenu of help. ...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8243
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4606
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.