p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

xslt thread: problem generating html ouput


Message #1 by Asif Saleem <asif@d...> on Tue, 18 Jun 2002 19:40:21 +0100
Remember that there are built-in template rules for every element that
cause the text to be copied to the output. You need to override these if
you want different behavior.

Michael Kay
Software AG
home: Michael.H.Kay@n...
work: Michael.Kay@s... 

> -----Original Message-----
> From: asif [mailto:asif@d...] 
> Sent: 19 June 2002 12:48
> To: P2P_XSLT
> Subject: [xslt] RE: problem generating html ouput
> 
> 
> I appreciate your help.
> 
> sorry but i am still confused by xsl parser behaviour as 
> modified xsl ouput's some xml tag values as well.
> 
> e.g. in html output displays  lb3d,  parallelImplementation 
> and fixed_input elements from xml files as well, while i only 
> expect it to generate 
> 	<h2>Input Parameters</h2>
> 	<h2>Input Parameters</h2>
> 
> 
> Thanks
> Asif
> --------------------------------
> xsl
> --------------------------------
> <xsl:stylesheet 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
> 
> <xsl:template match="x:name" 
> xmlns:x="http://www.iceni.ic.ac.uk/xmlSchema/idl">
> 
> 	<h2>Input Parameters</h2>
> 
> </xsl:template>
> 
> </xsl:stylesheet>
> ------------------------------
> html
> ------------------------------
> <?xml version="1.0" encoding="UTF-8"?>
>  lb3d
>  parallelImplementation
>  <h2 xmlns:x="http://www.iceni.ic.ac.uk/xmlSchema/idl">Input
> Parameters</h2> fixed_input_nx
>  <h2 xmlns:x="http://www.iceni.ic.ac.uk/xmlSchema/idl">Input
> Parameters</h2> fixed_input_nx
> ------------------------------
> 
> > Your XML source file uses a default namespace. This means you must 
> > write
> 
> <xsl:template match="x:name" 
> xmlns:x="http://www.st.co.uk/xmlSchema/idl">
> 
> to match the <name> element: If the name element in your 
> source document and the "name" in your stylesheet are in 
> different namespaces, then they won't match.
> 
> Michael Kay
> Software AG
> home: Michael.H.Kay@n...
> work: Michael.Kay@s... 
> 
> > -----Original Message-----
> > From: Asif Saleem [mailto:asif@d...]
> > Sent: 18 June 2002 19:40
> > To: P2P_XSLT
> > Subject: [xslt] problem generating html ouput
> > 
> > 
> > 
> > 
> > Hello,
> > 
> > I am new to xsl. I can't transform an xml file to html
> > properly. In the 
> > output html tags go missing.
> > 
> > Could somebody give me clue what's going wrong.
> > 
> > I have included the source files.
> > 
> > Thanks
> > Asif
> > 
> > ===========================
> > 1) imp.xml
> > ===========================
> > <?xml version="1.0" encoding="UTF-8"?>
> > <implementationDescriptionDocument
> >                 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> >                xmlns="http://www.st.co.uk/xmlSchema/idl"
> >                xmlns:ddl="http://www.st.co.uk/xmlSchema/ddl"
> >                xmlns:cdl="http://www.st.co.uk/xmlSchema/cdl" 
> > xsi:schemaLocation="http://www.st.co.uk/xmlSchema/idl 
> > /homes/asif/software/data/xml/cxml/IDL.xsd" name="lb3d 
> > implementationdefinitions">
> > 
> > <implementation
> > 
> ComponentDescriptionDocument="/homes/asif/data/xml/cxml/cdllb3d.xml">
> >   <componentName>lb3d</componentName>
> >   <implementationName>parallelImplementation</implementationName>
> > 
> > <portImplementation>
> >   <name>fixed_input_nx_in</name>
> > <dataStruct>fixed_input_nx</dataStruct>
> > </portImplementation>
> > 
> > <portImplementation>
> >   <name>fixed_input_nx_out</name>
> > <dataStruct>fixed_input_nx</dataStruct>
> > </portImplementation>
> > 
> > </implementation>
> > 
> > </implementationDescriptionDocument>
> > 
> > ===========================
> > 
> > 
> > 
> > ===========================
> > 2) imp.xsl
> > ===========================
> > <xsl:stylesheet
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
> > 
> > <xsl:template match="name">
> > 
> >         <h2>Input Parameters</h2>
> > 
> > </xsl:template>
> > 
> > </xsl:stylesheet>
> > 
> > 
> > ===========================
> > 
> > 
> > 
> > ===========================
> > 3) imp.java
> > ===========================
> > import java.io.File;
> > import java.io.StringReader;
> > import java.io.IOException;
> > import java.io.StringWriter;
> > import java.util.Hashtable;
> > import java.util.HashMap;
> > import java.util.Iterator;
> > import java.util.Enumeration;
> > import java.net.URL;
> > 
> > import javax.xml.transform.TransformerFactory;
> > import javax.xml.transform.Transformer;
> > import javax.xml.transform.Source;
> > import javax.xml.transform.Result;
> > import javax.xml.transform.Templates;
> > import javax.xml.transform.TransformerException;
> > import javax.xml.transform.TransformerConfigurationException;
> > import javax.xml.transform.sax.SAXResult;
> > import javax.xml.transform.sax.TemplatesHandler;
> > import javax.xml.transform.sax.TransformerHandler;
> > import javax.xml.transform.sax.SAXTransformerFactory;
> > import javax.xml.transform.dom.DOMSource;
> > import javax.xml.transform.dom.DOMResult;
> > import javax.xml.transform.stream.StreamSource;
> > import javax.xml.transform.stream.StreamResult;
> > 
> > import org.xml.sax.helpers.XMLReaderFactory;
> > import org.xml.sax.ContentHandler;
> > import org.xml.sax.SAXException;
> > import org.xml.sax.SAXParseException;
> > import org.xml.sax.XMLReader;
> > import org.w3c.dom.Node;
> > 
> > import java.io.*;
> > 
> > public class imp
> > {
> >      public static void main(String argv[])
> >      {
> >          if (argv.length < 1) {
> >              System.err.println ("Usage: xml_filename  xsl_filename
> > html_filename");
> >              System.exit (1);
> >          }
> > 
> >         try{
> >         SAXTransformerFactory saxTFactory = null;
> >         Transformer trans = null ;
> >         String xslURI = null;
> > 
> >         xslURI = new String(argv[1]);
> > 
> >        // attempt to instantiate a sax transformer factory
> >         TransformerFactory tFactory 
> > TransformerFactory.newInstance();
> >         if (tFactory instanceof SAXTransformerFactory) {
> >          saxTFactory = ((SAXTransformerFactory)tFactory);
> >        }
> >     if (saxTFactory == null) {
> >        System.out.println("XSLT() : unable to instantiate SAX 
> > transformer ! Please make sure the implementation you're 
> > using supports 
> > SAX Transformers");
> >      }
> >     if (saxTFactory != null)
> >         trans = saxTFactory.newTransformer(new 
> StreamSource(xslURI));
> >     if(trans != null)
> >         trans.transform(new StreamSource(argv[0]),new 
> > StreamResult(argv[2]));
> > 
> >           } catch (TransformerConfigurationException tce) {
> >              // Error generated by the parser
> >              System.out.println ("\n** Transformer Factory error");
> >              System.out.println("   " + tce.getMessage() );
> > 
> >              // Use the contained exception, if any
> >              Throwable x = tce;
> >              if (tce.getException() != null)
> >                  x = tce.getException();
> >              x.printStackTrace();
> >          } catch (TransformerException te) {
> >              // Error generated by the parser
> >              System.out.println ("\n** Transformation error");
> >              System.out.println("   " + te.getMessage() );
> >         
> >              // Use the contained exception, if any
> >              Throwable x = te;
> >              if (te.getException() != null)
> >                  x = te.getException();
> >              x.printStackTrace();
> > 
> >         }
> > 
> >      } // main
> > 
> > }
> > 
> > 
> > ===========================
> > 
> > 
> > 
> > ===========================
> > 4) output.html
> > ===========================
> > <?xml version="1.0" encoding="UTF-8"?>
> > 
> >   lb3d
> >   parallelImplementation
> > 
> >   fixed_input_nx_in fixed_input_nx
> > 
> > 
> >   fixed_input_nx_out fixed_input_nx
> > 
> > ===========================
> > 
> > 
> > As you can see no html tags generated by default parser in jdk 1.3
> 


  Return to Index