cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick <goup...@muss.cis.mcmaster.ca>
Subject Namespaces problem when using XSP or XSLT
Date Fri, 16 Jul 2004 16:45:18 GMT
Hi everybody,

I just run into a very interesting behavior of XSP (I guess this would 
also apply to any XSLT transformation). It temporarily ( XSLT seem to do 
it permanently ) removes name spaces from the files. To be more 
specific, the name spaces are not there when SAX events occur, but they 
appear when the document is serialized.

Name spaces are pretty important, so take a look at this example:

PIPELINES - There are three pattern that do the same thing - they 
generate and serialize SAX events. Nothing more, dead simple

  <map:pipeline>
        <!-- XSP -->
      <map:match pattern="simple-xsp">
          <map:generate type="serverpages" src="simple-query.xsp"/>
          <map:transform type="log">
              <map:parameter name="logfile" value="simple-xsp.txt"/>
              <map:parameter name="append" value="no"/>
          </map:transform>
          <map:serialize type="xml"/>
      </map:match>

        <!-- FILE -->      
      <map:match pattern="simple-file">
          <map:generate src="simple-query.xml"/>
          <map:transform type="log">
              <map:parameter name="logfile" value="simple-file.txt"/>
              <map:parameter name="append" value="no"/>
          </map:transform>
          <map:serialize type="xml"/>
      </map:match>

        <!-- JX -->      
    <map:match pattern="simple-jx">
          <map:generate type="jx" src="simple-query.jx">
              <map:parameter name="ref" value="true"/>
          </map:generate>
          
          <map:transform type="log">
              <map:parameter name="logfile" value="simple-jx.txt"/>
              <map:parameter name="append" value="no"/>
          </map:transform>
          <map:serialize type="xml"/>
    </map:match>
  </map:pipeline>

Now, let's take a closer look at each of those patterns.

XSP
Simple-query.xsp - this could not be any simpler. Generates 2 XML tags - 
<page><topicRef/></page>

<?xml version="1.0"?>
<xsp:page language="java" xmlns:xsp="http://apache.org/xsp" 
xmlns:db="http://apache.org/cocoon/xmldb/1.0">

    <xsp:logic>
        String baseName = new String("Test");
    </xsp:logic>
    
    <page>
        <topicRef xlink:href="#text" 
xmlns:xlink="http://www.w3.org/1999/xlink"><xsp:expr>baseName</xsp:expr></topicRef>
    </page>
</xsp:page>

The output produced is the following (exactly as expected, but keep on 
reading it will get more interesting at the end):

<?xml version="1.0" encoding="ISO-8859-1"?>
<page xmlns:xsp="http://apache.org/xsp" 
xmlns:db="http://apache.org/cocoon/xmldb/1.0">
        <topicRef xlink:href="#text" 
xmlns:xlink="http://www.w3.org/1999/xlink">Test</topicRef>
    </page>

FILE
Simple-query.xml - Again, an extremely simple XML file that we read and 
serialize:

<?xml version="1.0" encoding="ISO-8859-1"?>

<page xmlns:xsp="http://apache.org/xsp" 
xmlns:db="http://apache.org/cocoon/xmldb/1.0">
    <topicRef xlink:href="#text" 
xmlns:xlink="http://www.w3.org/1999/xlink">Test</topicRef>
</page>

Output of the "simple-file" pipeline is this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<page xmlns:xsp="http://apache.org/xsp" 
xmlns:db="http://apache.org/cocoon/xmldb/1.0">
    <topicRef xlink:href="#text" 
xmlns:xlink="http://www.w3.org/1999/xlink">Test</topicRef>
</page>

JX
Simple-file.jx - Almost identical to Simple-query.xml, with the only 
difference that text of the topicRef is generated from the request 
parameters.

<?xml version="1.0" encoding="ISO-8859-1"?>

<page xmlns:xsp="http://apache.org/xsp" 
xmlns:db="http://apache.org/cocoon/xmldb/1.0" >
    <topicRef xlink:href="#text" 
xmlns:xlink="http://www.w3.org/1999/xlink">${request.getParameter("ref")}</topicRef>
</page>

The output, when accessed as URL_PATH/simple-jx?ref=Test is this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<page xmlns:xsp="http://apache.org/xsp" 
xmlns:db="http://apache.org/cocoon/xmldb/1.0">
    <topicRef xlink:href="#text" 
xmlns:xlink="http://www.w3.org/1999/xlink">Test</topicRef>
</page>


In other words, you don't need a Cray to verify that the outcome of 
these three pipelines is IDENTICAL!!! The strangest thing was observed 
when I compared the output of the log transformers (enclosed after this 
message - differences are highlighted by *). All the name spaces would 
disappear form <page> tag when processed by the XSP, however, everything 
will be set back to normal when serialized (look at the outputted XML). 
JX and FILE generators would keep the name spaces intact.

The natural question to ask is why is it important if the result is the 
same. Well, the motivation behind it is to use XUpdate with 
XMLDBTransformer to interact with an eXist database (I made a post about 
that problem a few days ago). If I try to use XSP (or XSLT) to prepare 
the query, it would produce a failure. Exactly the same query (I used 
the same pipeline, but placed serializer before the XMLDB transformer, 
then saved the content as an XML file and used this new file with file 
generator and XMLDB transformer) worked out just fine with the name 
spaces manually added to the XML. Also, in case I remove the name space 
prefix form the XSP ( or XSLT ) then the SAME query works just fine with 
XSP ( XSLT ).

So the question is - what happens to the name spaces? Why are they being 
removed temporarily and then restored again? Is it a bug or is it me who 
don't possess sufficient knowledge of XML/XSL and Cocoon?

Thank you.

Sincerely,
Nick.

FOR XSP:
[setup] ---------------------------- [Fri Jul 16 11:07:47 EDT 2004] 
----------------------------
[setDocumentLocator] systemid=file:/C:/Simple/simple-query.xsp,publicid=null
[startDocument]
[startPrefixMapping] prefix=xml,uri=http://www.w3.org/XML/1998/namespace
[startPrefixMapping] prefix=xsp,uri=http://apache.org/xsp
[startPrefixMapping] prefix=db,uri=http://apache.org/cocoon/xmldb/1.0
[startElement] uri=,local=page,raw=page
[characters]
        
[startPrefixMapping] prefix=xlink,uri=http://www.w3.org/1999/xlink
[startElement] uri=,local=topicRef,raw=topicRef
[            ] 1. 
uri=http://www.w3.org/1999/xlink,local=href,qname=xlink:href,type=CDATA,value=#text
[characters] Test
[endElement] uri=,local=topicRef,raw=topicRef
[endPrefixMapping] prefix=xlink
[characters]
    
[endElement] uri=,local=page,raw=page
[endPrefixMapping] prefix=xml
[endPrefixMapping] prefix=xsp
[endPrefixMapping] prefix=db
[endDocument]


FOR FILE:
[setup] ---------------------------- [Fri Jul 16 11:07:56 EDT 2004] 
----------------------------
[setDocumentLocator] systemid=file:/C:/Simple/simple-query.xml,publicid=null
[startDocument]
[startPrefixMapping] prefix=xsp,uri=http://apache.org/xsp
[startPrefixMapping] prefix=db,uri=http://apache.org/cocoon/xmldb/1.0
[startElement] uri=,local=page,raw=page
*[            ] 1. 
uri=,local=,qname=xmlns:xsp,type=CDATA,value=http://apache.org/xsp*
*[            ] 2. 
uri=,local=,qname=xmlns:db,type=CDATA,value=http://apache.org/cocoon/xmldb/1.0*
[characters]
    
[startPrefixMapping] prefix=xlink,uri=http://www.w3.org/1999/xlink
[startElement] uri=,local=topicRef,raw=topicRef
[            ] 1. 
uri=http://www.w3.org/1999/xlink,local=href,qname=xlink:href,type=CDATA,value=#text
*[            ] 2. 
uri=,local=,qname=xmlns:xlink,type=CDATA,value=http://www.w3.org/1999/xlink*
[characters] Test
[endElement] uri=,local=topicRef,raw=topicRef
[endPrefixMapping] prefix=xlink
[characters]

[endElement] uri=,local=page,raw=page
[endPrefixMapping] prefix=xsp
[endPrefixMapping] prefix=db
[endDocument]

FOR JX:
[setup] ---------------------------- [Fri Jul 16 11:08:02 EDT 2004] 
----------------------------
[setDocumentLocator] 
systemid=file:/C:/eclipse/workspace/Tapor-Portal/Testing/Simple/simple-query.jx,publicid=null
[startDocument]
[startPrefixMapping] prefix=xsp,uri=http://apache.org/xsp
[startPrefixMapping] prefix=db,uri=http://apache.org/cocoon/xmldb/1.0
[startElement] uri=,local=page,raw=page
*[            ] 1. 
uri=,local=,qname=xmlns:xsp,type=CDATA,value=http://apache.org/xsp*
*[            ] 2. 
uri=,local=,qname=xmlns:db,type=CDATA,value=http://apache.org/cocoon/xmldb/1.0*
[characters]
    
[startPrefixMapping] prefix=xlink,uri=http://www.w3.org/1999/xlink
[startElement] uri=,local=topicRef,raw=topicRef
[            ] 1. 
uri=http://www.w3.org/1999/xlink,local=href,qname=xlink:href,type=CDATA,value=#text
*[            ] 2. 
uri=,local=,qname=xmlns:xlink,type=CDATA,value=http://www.w3.org/1999/xlink*
[characters] Test
[endElement] uri=,local=topicRef,raw=topicRef
[endPrefixMapping] prefix=xlink
[characters]

[endElement] uri=,local=page,raw=page
[endPrefixMapping] prefix=xsp
[endPrefixMapping] prefix=db
[endDocument]


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message