You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@forrest.apache.org by Ferdinand Soethe <fe...@apache.org> on 2005/07/25 06:56:37 UTC

Error transforming Table IDs

There seems to be an error in the transformation of table id-Attributes in the
current skin.

A sequence like this

<p>Zur Zeit gehören ihr folgende Mitglieder an:</p>
<table id="ueber_uns_teilmehmer">
  <tr><td><p>
    <a href="http://www.aldebaran.de">aldebaran Daten- und Kommunikationssysteme GmbH</a>
    <br/>IT-Dienstleister aus Hannover.</p></td><td><img class="aldebaranLogo" src="images/LogoAldebaran.gif" alt="Aldebaran
      Logo"/></td></tr>

is transformed into


<p>Zur Zeit geh&ouml;ren ihr folgende Mitglieder an:</p>
    
    
<a name="ueber_uns_teilmehmer"></a>
<table class="ForrestTable" cellspacing="1" cellpadding="4">
      
<tr>
<td colspan="1" rowspan="1">
<p>        
        
<a href="http://www.aldebaran.de">aldebaran Daten- und Kommunikationssysteme GmbH</a>
        
<br>IT-Dienstleister aus Hannover.</p>
</td><td colspan="1" rowspan="1"><img alt="Aldebaran           Logo" class="aldebaranLogo" src="images/LogoAldebaran.gif"></td>

</tr>


As you can see the id-attribute is no longer an id but a local anchor
before the table.

--
Ferdinand Soethe


Re: Error transforming Table IDs

Posted by Ross Gardler <rg...@apache.org>.
Ross Gardler wrote:
> Ferdinand Soethe wrote:
> 
> ...
> 
>> Attempted Solution:
>>
>> 1  <xsl:template match="node()|@*" priority="-1">
>>      <!-- id processing will create its own a-element so processing 
>> has to
>>           happen outside the copied element
>>      -->
>> 2   <xsl:apply-templates select="@id"/>
>> 3    <xsl:copy>
>> 4      <xsl:apply-templates select="@* and ???"/>
>> 5       <xsl:attribute name="id">{id}</xsl:attribute>
>>        <xsl:apply-templates/>
>>      </xsl:copy>
>>    </xsl:template>
>>
> 
> ...
> 
>> Line 4 should now exclude @id but I'm not sure how to express that in
>>        X-Path if I want to process all attributes but id? Can someone
>>        pls help?
> 
> 
> Something like the following should do it:
> 
> <xsl:apply-tempaltes select="@*[name(.) !- 'id']/>

Sorry, too many typo's in that, it should read:

<xsl:apply-templates select="@*[name(.) != 'id']"/>


Re: Error transforming Table IDs

Posted by Ross Gardler <rg...@apache.org>.
Ferdinand Soethe wrote:

...

> Attempted Solution:
> 
> 1  <xsl:template match="node()|@*" priority="-1">
>      <!-- id processing will create its own a-element so processing has to
>           happen outside the copied element
>      -->
> 2   <xsl:apply-templates select="@id"/>
> 3    <xsl:copy>
> 4      <xsl:apply-templates select="@* and ???"/>
> 5       <xsl:attribute name="id">{id}</xsl:attribute>
>        <xsl:apply-templates/>
>      </xsl:copy>
>    </xsl:template>
> 

...

> Line 4 should now exclude @id but I'm not sure how to express that in
>        X-Path if I want to process all attributes but id? Can someone
>        pls help?

Something like the following should do it:

<xsl:apply-tempaltes select="@*[name(.) !- 'id']/>

Ross

Re: Error transforming Table IDs

Posted by Ferdinand Soethe <fe...@apache.org>.
OK, I think I found the culprit for the strange behavior with
IMG-elements.

The Problem:

After fixing the problem of id-attributes not being passed
through to the final HTML I notices a strange behaviour with
IMG-elements:

- If an IMG-element had no id-attribute everything worked fine. IMG
  was processed as expected.
- If it had an id-attribute however strange things happended, the
  IMG-element was renderered like this

  <img alt="Icon"><a name="icon"></a> which obviously made it pretty
  useless.

Analysis:

Going down the pipeline I found the culprit in pelts document2html
where img is processed as part of this default template:

1  <xsl:template match="node()|@*" priority="-1">
2    <xsl:copy>
3      <xsl:apply-templates select="@*"/>
4      <xsl:apply-templates/>
5    </xsl:copy>
6  </xsl:template>

Debugging this I found line 3 starting to copy the IMG-element then
trying to execute the following template

 <!-- Generate a <a name="..."> tag for an @id -->
  <xsl:template match="@id">
    <xsl:if test="normalize-space(.)!=''">
      <a name="{.}"/>
    </xsl:if>
  </xsl:template>

which tries to insert a a-element right into our open img-element,
triggering an error and aborting the processing (which explains the
strange result).

Attempted Solution:

1  <xsl:template match="node()|@*" priority="-1">
     <!-- id processing will create its own a-element so processing has to
          happen outside the copied element
     -->
2   <xsl:apply-templates select="@id"/>
3    <xsl:copy>
4      <xsl:apply-templates select="@* and ???"/>
5       <xsl:attribute name="id">{id}</xsl:attribute>
       <xsl:apply-templates/>
     </xsl:copy>
   </xsl:template>

Line 2 will only process ids and insert the a-element before the
       img-tag as usual (question: does it make sense to have this
       id-processing here AND in several templates that I saw in
       common? That seems to invite redundant processing?)

Line 4 should now exclude @id but I'm not sure how to express that in
       X-Path if I want to process all attributes but id? Can someone
       pls help?

Line 5 inserts the unprocessed id-attribute for use in css-styling.

So wdyt?


--
Ferdinand Soethe


Re: Error transforming Table IDs

Posted by Ross Gardler <rg...@apache.org>.
Ferdinand Soethe wrote:
> Have started to try and figure out the remaining problem by
> debug-logging the Forrest transformations of xdocs.

...

> Can anybody tell me how to make cocoon simply write the xml-stream
> into a named xml-document?

I comment out the transforms after the one I want to see then request 
the file directly. If this is no good for your case then you can write 
to a named XML document with the SourceWritingTransformer - see 
http://cocoon.apache.org/2.1/userdocs/transformers/sourcewriting-transformer.html

Ross

Re: Error transforming Table IDs

Posted by Ferdinand Soethe <fe...@apache.org>.
Have started to try and figure out the remaining problem by
debug-logging the Forrest transformations of xdocs.

I'm currently using snippets like this

        <!-- Test insert FSO -->
        <map:transform type="debugLogger">
          <map:parameter name="logfile" value="P:\01-soure.log"/>
          <map:parameter name="append" value="false"/>
        </map:transform>

to take a look inside each step
of a pipeline, but unfortuntately results like this

     [startElement] uri=,local=document,raw=document
     [characters]

     [startElement] uri=,local=header,raw=header
     [characters]

     [startElement] uri=,local=title,raw=title
     [characters] Test document
     [endElement] uri=,local=title,raw=title
     [characters]

     [endElement] uri=,local=header,raw=header
     [characters]

are kind of hard to read.

Can anybody tell me how to make cocoon simply write the xml-stream
into a named xml-document?

Thanks,
        
--
Ferdinand Soethe


Re: Error transforming Table IDs

Posted by Ferdinand Soethe <fe...@apache.org>.
Ferdinand Soethe wrote:

> OK, I fixed the pass-through of id for several elements in common and
> pelt but did not go for the wider solution you suggested because I was
> not sure of the consequences.

There is still some weired behaviour happening when I change the class
attribute in <img> to an id-attribute. Will try again in the morning.
Can anybody point me to the processing pipeline responsible for
imgs in docv20?


Thanks,
--
Ferdinand Soethe


Re: Error transforming Table IDs

Posted by Ferdinand Soethe <fe...@apache.org>.
Thorsten Scherler wrote:

> I am more for 
> <xsl:copy-of select="@*"/>

> That will be better for maintainment. I could not see anything in the
> code that would speak against that and the fix you suggested. 

OK, I fixed the pass-through of id for several elements in common and
pelt but did not go for the wider solution you suggested because I was
not sure of the consequences.

--
Ferdinand Soethe


Re: Error transforming Table IDs

Posted by Thorsten Scherler <th...@apache.org>.
On Mon, 2005-07-25 at 15:44 +0200, Ferdinand Soethe wrote:
> Looks like an oversight. When (in file
> main\webapp\skins\common\xslt\html\document2html.xsl)
> 
> <xsl:template match="table">
>     <xsl:apply-templates select="@id"/>
>     <table cellpadding="4" cellspacing="1" class="ForrestTable">
>       <xsl:copy-of select="@cellspacing | @cellpadding | @border |
>       @class | @bgcolor"/>
>       <xsl:apply-templates/>
>     </table>
>   </xsl:template>
> 
> id is used to apply a templates that creates the local anchor (to make
> ids addressable with local anchors) the id-attribute is 'used up' in
> the process instead of also being copied over in
> 
> <xsl:copy-of select="@cellspacing | @cellpadding | @border | @class | @bgcolor"/>
> 
> Adding @id to the list of copied attributes fixes the problem.
> 
> <xsl:copy-of select="@cellspacing | @cellpadding | @border | @class | @bgcolor |@id"/>
> 
> In my view this fix should be applied to all elements that use 'up id' in
> this way. Any reason not to do that?
> 

I am more for 
<xsl:copy-of select="@*"/>

That will be better for maintainment. I could not see anything in the
code that would speak against that and the fix you suggested. 

salu2
thorsten
> 
> --
> Ferdinand Soethe
> 
-- 
thorsten

"Together we stand, divided we fall!" 
Hey you (Pink Floyd)


Re: Error transforming Table IDs

Posted by Ferdinand Soethe <fe...@apache.org>.
Looks like an oversight. When (in file
main\webapp\skins\common\xslt\html\document2html.xsl)

<xsl:template match="table">
    <xsl:apply-templates select="@id"/>
    <table cellpadding="4" cellspacing="1" class="ForrestTable">
      <xsl:copy-of select="@cellspacing | @cellpadding | @border |
      @class | @bgcolor"/>
      <xsl:apply-templates/>
    </table>
  </xsl:template>

id is used to apply a templates that creates the local anchor (to make
ids addressable with local anchors) the id-attribute is 'used up' in
the process instead of also being copied over in

<xsl:copy-of select="@cellspacing | @cellpadding | @border | @class | @bgcolor"/>

Adding @id to the list of copied attributes fixes the problem.

<xsl:copy-of select="@cellspacing | @cellpadding | @border | @class | @bgcolor |@id"/>

In my view this fix should be applied to all elements that use 'up id' in
this way. Any reason not to do that?


--
Ferdinand Soethe