Page: http://wiki.cocoondev.org/Wiki.jsp?page=HtmlTableCellNonBlanking , 
version: 17 on Tue May 27 22:55:00 2003 by JoergHeinicke

- !!Automatically Inserting Non-Blanking Spaces Into Empty Table Cells
?                                ^ -

+ !!Automatically Inserting Non-Breaking Spaces Into Empty Table Cells
?                                ^^

+ Many browsers suffer from the ''feature'' that they omit the table borders 
from empty cells which. You have different possibilities to solve this issue.
- Many browsers suffer from the ''feature'' that they omit the table
- borders from empty cells which. The traditional solution to
- this problem is to insert a non-blanking space ({{ }}) into 
- empty cells.
+ ! CSS property {{empty-cells}}:
- \\
- The following XSLT snippet, a {{xsl:template}} match, activates on 
- encountering a table cell and replaces empty cells and cells that 
- contain only whitespace with a non-blanking space. 
- \\
- \\
- To use this code, simply copy the snippet into one our your xsl
- stylesheets.
- 
- !XSLT Code Snippet
+ table {
+     empty-cells: show;
+ }
-   <xsl:template match="td">
-     <td>
-       <xsl:choose>
-         <!-- If cell has child node or contains text then output them -->
-         <xsl:when test="count(./*) > 0 or normalize-space() != ''">
-           <xsl:apply-templates/> 
-         </xsl:when>
-         <!-- Otherwise the cell is empty and we output a '  ' -->
-         <xsl:otherwise>
-           <xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
-         </xsl:otherwise>
-       </xsl:choose>
-     </td>
-   </xsl:template>
- !!Notes
+ The default value is {{collapse}}, so empty cells are not shown. More info 
you can find in the [CSS 2 
spec|http://www.w3.org/TR/REC-CSS2/tables.html#empty-cells].
+ \\
+ ! Non-breaking space via XSLT:
- * The function {{count(./*)}} returns the number of child nodes
-   belonging to the table cell.
- * The XSLT function {{normalize-space}} removes leading and
-   trailing white space. This helps us to determine if the cell's 
-   text is really empty.
+ The following XSLT snippet, a {{xsl:template}} match, activates on 
encountering a table cell and replaces empty cells and cells that contain only 
whitespace with a non-breaking space. 
+ \\
+ To use this code, simply copy the snippet into one of your XSLT stylesheets.
- * Use {{disable-output-escaping}} to output the non-blanking space.
+ {{{
+ <xsl:template match="td">
+     <td>
+         <xsl:choose>
+             <!-- If cell has child nodes or contains text then output them -->
+             <xsl:when test="* or normalize-space()">
+                 <xsl:apply-templates/> 
+             </xsl:when>
+             <!-- Otherwise the cell is empty and we output a non-breaking 
space -->
+             <xsl:otherwise>
+                 <xsl:text>&amp;#160;</xsl:text>
+             </xsl:otherwise>
+         </xsl:choose>
+     </td>
+ </xsl:template>
+ }}}
+ ! Notes
+ 
+ * The expression in the {{test}} attribute is evaluated to a boolean value.
+ * {{*}} is evaluated to true if a child element exists.
+ * {{normalize-space()}} is evaluated to true if the function returns a 
string. All descendant text nodes of the context {{td}} element are 
concatenated, leading and trailing whitespace characters are removed. Multiple 
spaces, tabs and new line characters are replaced by a single space. More info 
in the [XPath spec|http://www.w3.org/TR/xpath#function-normalize-space].
+ * &amp;#160; is the character reference for the non-breaking space.
- -- ''[Alan Hodgkinson]''
+ -- based on a solution provided by ''[Alan Hodgkinson]''.
- !! Reader comments
+ ! Further comments
- ! Use entities
- Alternatively, define the {{ }} entity at the beginning of your stylesheet 
with:\\
- {{<!DOCTYPE stylesheet [ <!ENTITY nbsp " " >\>}}\\
- This means you can use {{ }} as per HTML.
+ If &amp;#160; is not the solution you prefer, but you want to use the 
&#amp;nbp; known from HTML, you can add an entity to the XSLT stylesheet in 
front of the {{xsl:stylesheet}} root element:
+ {{{
+ <!DOCTYPE xsl:stylesheet [
+ <!ENTITY nbsp "&amp;#160;">
+ ]>
+ }}}
- -- Anonymous author
+ More info in the [XML spec|http://www.w3.org/TR/REC-xml#sec-internal-ent].
+ -- based on a solution provided by ''Anonymous author''.
- ! disable-output-escaping considered harmful 
- Quoting a message from Michael Kay 
([http://p2p.wrox.com/archive/xslt/2001-03/10.asp]):
+ The originally posted solution by Alan Hodgkinson uses 
{{disable-output-escaping}}, but this is not recommended:
- ''...Cocoon, I think, does further processing of the XSLT output. This is 
exactly
- the scenario that makes "disable-output-escaping" bad programming practice,
- and the reason that the XSLT spec says processors aren't obliged to support
- it. Basically, if the XSLT output is serialized to text and sent straight to
- the browser, your're probably OK, but if the output is a tree that is then
- input to further stages of processing, then you aren't...''
- The "use entities" suggestion above has the big advantage of not requiring 
d-o-e.
+ {{{
+ <xsl:text disable-output-escaping="yes">&amp;amp;nbsp;</xsl:text>
+ }}}
- -- [Bertrand Delacretaz]
+ Quoting a message from Michael Kay from March 2001:
- ! change disable-output-escaping to the right entity
+ "...Cocoon, I think, does further processing of the XSLT output. This is 
exactly the scenario that makes "{{disable-output-escaping}}" bad programming 
practice, and the reason that the XSLT spec says processors aren't obliged to 
support it. Basically, if the XSLT output is serialized to text and sent 
straight to the browser, your're probably OK, but if the output is a tree that 
is then input to further stages of processing, then you aren't..."
- If you replace 'ampersand-nbsp-semicolon' with 'ampersand-hash-160-semicolon' 
you have very quick solution!
+ J. Pietschmann provided a [collection of several 
issues|http://marc.theaimsgroup.com/?l=xml-cocoon-users&m=105362820521196&w=2]:
- -- Marcin 
+ "A JAXP conformant XSLT processor may generate PIs embedded in the output to 
signal a {{disable-output-escaping="yes"}} to downstream processing stages. If 
the serializer finally gets these PIs and
+ understands them, d-o-e will work fine even in Cocoon.
+ \\
+ However, there's plenty of stuff that can go wrong:
+ # The d-o-e'd stuff is still text to downstream XML processing stages, it 
can't be processed as elements.
+ # Generating the PIs is not required. Xalan does, I'm not sure whether Saxon 
does.
+ # The PIs are not standardized. So you'd better use an identity 
transformation with the same XSLT processor which generates them for 
serialization. Fortunately, Cocoon does exactly this. Nevertheless, if you mix 
processors, you're likely to get trouble.
+ # If some processing stage decides to eat or mangle the PIs or to change 
their position relative to the stuff intended to be d-o-e'd, you're hosed."
+ 
+ Other stuff about {{disable-output-escaping}} can be found in the [XSLT 
FAQ|http://www.dpawson.co.uk/xsl/sect2/N2215.html].
- I believe that a comment is just as good as a space as far as NS is 
concerned. It's a bit bigger, but it has the advantage that it's not really 
"content", so it shouldn't affect formatting as much as a space, which a 
browser will be rendering in a particular font, hence it will have some "size". 
?                                                                ^

+ I believe that a comment is just as good as a space as far as Netscape is 
concerned. It's a bit bigger, but it has the advantage that it's not really 
"content", so it shouldn't affect formatting as much as a space, which a 
browser will be rendering in a particular font, hence it will have some "size". 
?                                                                ^^^^^^^

-       <xsl:copy>
? ^

+     <xsl:copy>
? ^^^^

-               <xsl:copy-of select="@*"/>
? ^^

+         <xsl:copy-of select="@*"/>
? ^^^^^^^^

-               <xsl:comment>NS hack</xsl:comment>
? ^^

+         <xsl:comment>NS hack</xsl:comment>
? ^^^^^^^^

-               <xsl:apply-templates/>
? ^^

+         <xsl:apply-templates/>
? ^^^^^^^^

-       </xsl:copy>
? ^

+     </xsl:copy>
? ^^^^

+ -- ''[Con]''.
- ----
- [Con]


Page: http://wiki.cocoondev.org/Wiki.jsp?page=LeftMenu , version: 72 on Tue May 
27 22:08:08 2003 by 62.3.65.237

- [Aboutssss]\\
?       ----

+ [About]\\


Reply via email to