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

Re: [xsl] simplify XPath expression


Subject: Re: [xsl] simplify XPath expression
From: Christof Höke <christof.hoeke@xxxxxxx>
Date: Thu, 22 Jan 2004 09:54:12 +0100

Lars Huttar wrote:

hi,
i was thinking the following xpath could be simplified as it has redundant infos. but somehow i cannot bring this to work:



combilist/item/head[1][not(../date)] [not(../image) and count(../description)=1] | combilist/item/head[2][not(../price)] [not(../image) and count(../description)=1]


the second line in each member of the above union is the same so i think it must be possible to combine these. i tried


(
	combilist/item/head[1][not(../date)]
	|
	combilist/item/head[2][not(../price)]
)
[not(../image) and count(../description)=1]

but this does not work...


Can you specify in what way it does not work?
Is there an XPath syntax error?
Or does it give you an unexpected result?
If the latter, what result did you get?

Lars


sorry. tried it in a simplified example again and in e.g. xmlspy the following works:


<xsl:template match="(a | b) [@att='1']">
	<xsl:apply-templates/>
</xsl:template>

but i run the above example in a (very simple) jython servlet in Tomcat 5 which does nothing more than a transformation using Java JDK 1.4.2. with the included xalan. i include the relevant servlet and error message.

i guess this would be more a xalan/jdk/tomcat/jython problem and this might not be the right NG.
anyway, maybe someone knows why this does not work?


thanks
chris


# jython servlet relevant section: ################################## import javax import javax.xml.transform.stream.StreamSource as StreamSource import javax.xml.transform.stream.StreamResult as StreamResult import javax.xml.transform.TransformerFactory as TransformerFactory

class test(javax.servlet.http.HttpServlet):
	
	def doGet(self, req, res):		
		res.contentType = "text/html"
		self.out = res.outputStream

		xmlfile = '/test/test.xml'
		tf = self.getTransformer('/test/test.xsl')
		self.transform(xmlfile, tf)

	def getTransformer(self, xsl):
		xslId = self.ctx.getResource(xsl).toExternalForm()
		xsl = StreamSource(xslId)
		tf = TransformerFactory.newInstance().newTransformer(xsl)
		return tf

	def transform(self, xml, tf):
		xmlId = self.ctx.getResource(xml).toExternalForm()
		xml = StreamSource(xmlId)
		tf.transform(xml, StreamResult(self.out))
#####################



# error message in browser
##########################

"javax.xml.transform.TransformerException: Es wurde ein Knotentest erwartet, der entweder NCName:* oder QName entspricht."

which would be translate to something like:
"javax.xml.transform.TransformerException: A Nodetest was expected which is wether NCName:* or QName"



Traceback (innermost last):
(no code object) at line 0
javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: Es wurde ein Knotentest erwartet, der entweder NCName:* oder QName entspricht.


at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:805)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:324)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)

at org.python.core.PyMethod.__call__(PyMethod.java)

at org.python.core.PyObject.__call__(PyObject.java)

at org.python.core.PyInstance.invoke(PyInstance.java)

at org.python.pycode._pyx0.getTransformer$4(E:\webapps\test.py:30)

at org.python.pycode._pyx0.call_function(E:\webapps\test.py)

at org.python.core.PyTableCode.call(PyTableCode.java)

at org.python.core.PyTableCode.call(PyTableCode.java)

at org.python.core.PyFunction.__call__(PyFunction.java)

at org.python.core.PyInstance.invoke(PyInstance.java)

at org.python.pycode._pyx0.doGet$3(E:\webapps\test.py:24)

at org.python.pycode._pyx0.call_function(E:\webapps\test.py)

at org.python.core.PyTableCode.call(PyTableCode.java)

at org.python.core.PyTableCode.call(PyTableCode.java)

at org.python.core.PyTableCode.call(PyTableCode.java)

at org.python.core.PyFunction.__call__(PyFunction.java)

at org.python.core.PyMethod.__call__(PyMethod.java)

at org.python.core.PyObject.__call__(PyObject.java)

at org.python.core.PyObject._jcallexc(PyObject.java)

at org.python.proxies.main$test$0.doGet(Unknown Source)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)

at org.python.proxies.main$test$0.service(Unknown Source)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

at org.python.util.PyServlet.service(PyServlet.java)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)

at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:564)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)

at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:211)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:805)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:696)

at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:605)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:677)

at java.lang.Thread.run(Thread.java:534)

Caused by: javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: Es wurde ein Knotentest erwartet, der entweder NCName:* oder QName entspricht.

at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:984)

at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:788)

... 52 more


...





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




Current Thread
Keywords