You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Gary L Peskin <ga...@firstech.com> on 2001/02/22 02:46:23 UTC

Re: problem with namespaces .. [MORE INFO- looks like a bug]...using the SimpleTransform example + e xamples

Patrick Moore wrote:
> 
> This appears to be a bug:
> 
>             <PLAYTIME>
>                 <rioport:min2sec>
>                     <xsl:value-of select="TRACK_PLAYTIME/text()" />
>                 </rioport:min2sec>
>             </PLAYTIME>
> 
> In the min2sec code I print out the child nodes of the Context node as
> returned by XSLProcessorContext.getContextNode() [see code snippet below].
> The child nodes printed out are the TRACK_PLAYTIME's parent's child nodes. I
> tried using xsl:copy-of and got the same result.
> 
> for ( node = context.getContextNode().getFirstChild();
>           node != null; node = node.getNextSibling()) {
> System.out.println(node.getClass().getName() );
>         if ( node.getNodeType() == Node.TEXT_NODE ) {
> System.out.println("value:"+node.getNodeValue());
>         }
> }

This is what I was alluding to in my earlier message.  It's not a Xalan
bug.  The context node for a template comes from the current node for
the template.  The current node for the template is basically the node
which caused the template to be chosen.  In your case, that is the
<TRACK> node.  So, you'll get all of the children of the <TRACK> node. 
The text nodes that you're seeing with just a newline for content are
the whitespace nodes between the various elements that are the children
of <TRACK>.

If I were you, I'd shelve the extension element and create an extension
function, passing the text time, like this:

  <PLAYTIME>
    <xsl:value-of select="rioport:min2sec(string(TRACK_PLAYTIME))"/>
  </PLAYTIME>

I think this is what you want to do.

Gary

jsp xsl problem

Posted by "陳照東) <alex@erp.ncu.edu.tw>" <Alex>.
below is my jsp code try to transform the xml to string by xsl, i use
Xalan2, but it cant work.......please help me...

<%@ page language="java" %>
<%@ page import="java.io.*"%>
<%@ page import="org.apache.xalan.xpath.xml.XMLParserLiaison"%>
<%@ page import="org.apache.xalan.xslt.*"%>
<%@ page import="org.apache.xerces.framework.XMLParser"%>
<%@ page import="org.apache.xerces.parsers.DOMParser"%>
<%@ page import="org.w3c.dom.Node"%>

<%
XSLTProcessor xsltproc=XSLTProcessorFactory.getProcessor(new
XMLParserLiaison());

StringWriter stringwriter=new StringWriter();
String xmlname="stamps.xml";
String xslname="stampTest.xsl";
String filename1=application.getRealPath("/xml/"+xmlname);
String filename2=application.getRealPath("/xml/"+xslname);
FileReader filereader=new FileReader(filename1);

XSLTInputSource xsltinputsource=new XSLTInputSource(filereader);
XSLTInputSource xsltinputsource1=new XSLTInputSource(filename2);
XSLTResultTarget xsltresulttarget=new XSLTResultTarget(stringwriter);
xsltproc.process(xsltinputsource,xsltinputsource1,xsltresulttarget);
String output=stringwriter.toString();
%>

<html>
<body>
test
</body>
</html>

****************************
but it get error like below:

: SAX Exception
javax.xml.transform.TransformerException: SAX Exception
java.lang.Throwable() java.lang.Exception()
org.xml.sax.SAXException(java.lang.Exception) void
org.apache.xalan.xslt.XSLTEngineImpl.error(int, java.lang.Object [],
 java.lang.Exception) void org.apache.xalan.xslt.XSLTEngineImpl.error(int,
java.lang.Exception) void
org.apache.xalan.xslt.XSLTEngineImpl.process(org.apache.xalan.xslt.XSLTInput
Source, org.apache.xalan.xslt.XSLTInputSource,

why???  i use Xalan2
what should  i do?????

Alex