new to test
    margins with unbreakable-spaces to keep formatting in copy/paste
    no more html <pre/> tag in hope that search/replace are not too long

----- Original Message -----
From: "Steven Noels" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, October 06, 2002 1:31 PM
Subject: Re: generic resources

> the collapse/expand function appears not to be working on my Mozilla 1.0
> under W2K.

Fixed for NS6-7, seems that DOM model is different between IE and mozilla
(empty text nodes are registred)
Orthogonal ids seems to work for me.

----- Original Message -----
From: "Ovidiu Predescu" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, October 04, 2002 7:55 AM
Subject: Re: generic resources

> (The colors are awful IMO, but
> that can be changed ;)

Cocoon colors I found, mine are theese ones.

> > About webapp hierarchy
> > For our apps, we usually share resources (like this one, or tuned error
> > messages and other xsl, js, css)
> > They are in a WEB-INF/res directory as if it was updatable (like a jar)
> > Some xsl seems to be duplicated in cocoon webapp, can't cocoon show a
> > good
> > practice on this question ?
>
> I think some of these duplicates are historic. You're more than welcome
> to point out these duplicates and provide a patch as an alternative.

simple-xml2html.xsl  appears in 3 places

src/webapp/stylesheets
src/webapp/cocoon/samples/hello-world/style/xsl
src/webapp/samples/common/style/xsl/html

and 4 sitemaps

src/webapp/sitemap.xmap
src/webapp/mount/lint/sitemap.xmap
src/webapp/samples/sitemap.xmap
src/webapp/samples/hello-world/sitemap.xmap

view-source.xsp is used in

src/webapp/sitemap.xmap
sub\sitemap.xmap

> Frédéric, would you like to pick up the task of refactoring the
> existing src/webapp/samples/sitemap.xmap to use your stylesheet instead
> of view-source.xsp? I'd gladly incorporate the changes, together with
> your stylesheet of course, into Cocoon.

I use this piece of code at top of root sitemap

<map:components>
        <map:generators default="xsp">
            <map:generator name="file"
src="org.apache.cocoon.generation.FileGenerator" label="content,data"
logger="sitemap.generator.file" pool-max="32" pool-min="8" pool-grow="4"/>
            <map:generator name="xsp"
src="org.apache.cocoon.generation.ServerPagesGenerator"
logger="sitemap.generator.serverpages" pool-max="32" pool-min="4"
pool-grow="2"/>
        </map:generators>

        <map:serializers default="html">
            <map:serializer name="html" mime-type="text/html"
src="org.apache.cocoon.serialization.HTMLSerializer">
                <encoding>iso-8859-1</encoding>
            </map:serializer>
            <map:serializer name="xhtml" mime-type="text/html"
logger="sitemap.serializer.xhtml"
src="org.apache.cocoon.serialization.XMLSerializer" pool-max="64"
pool-min="2" pool-grow="2">
                <doctype-public>-//W3C//DTD XHTML 1.0
Strict//EN</doctype-public>

<doctype-system>http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</doctype-s
ystem>
                <encoding>iso-8859-1</encoding>
            </map:serializer>
        </map:serializers>

</map:components>

        <map:pipeline id="utils">
            <!-- Utility for viewing generated source -->
            <map:match pattern="**.xsp2src">
                <map:generate type="xsp" src="{1}.xsp"/>
                <map:transform src="context://WEB-INF/res/xml.xsl"/>
                <map:serialize type="xhtml"/>
            </map:match>
            <!-- Utility for viewing source of a file -->
            <map:match pattern="**2file">
                <map:generate type="file" src="{1}"/>
                <map:transform src="context://WEB-INF/res/xml.xsl"/>
                <map:serialize type="xhtml"/>
            </map:match>
        </map:pipeline>


It's the fastest way I found to use it from browser.
For security reason, cocoon need perhaps to think before give this tip at
root sitemap, because web sites from cocoon newbies have then the key to be
understood. I can't take this decision alone.

> src/webapp/samples/docs/samples/slides/view-source.xsp
> is doing a similar job as your stylesheet, except that is a Java
> program hidden inside an XSP page, which constructs a DOM tree and
> walks on it to generate the output
If exigent code was needed (like in a browser for example), this kind of
generation could be useful for better handling of <![CDATA[ ]]>, or faster
search/replace. But even in this case, I would keep XSL transformation,
easier to ajust and modify presentation.
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="xml.xsl"?>
<!--
 |
 | displaying xml source in html
 | [EMAIL PROTECTED]
 |
 | fast test, apply this to itself
 |
 | usage :
 |   as a root xsl matching all elements
 |   as an import xsl to format some xml
 |     with <xsl:apply-templates select="node()" mode="src"/>
 |     in this case you need to copy css and js somewhere to link with
 |
 | features :
 |   DOM compatible toggle
 |   no extra characters to easy copy/paste code
 |   html formatting oriented for logical css
 |   commented to easier adaptation
 |   all xmlns:*="uri" attributes in root node
 |   text reformating ( xml entities )
 |
 | problems :
 |   <![CDATA[ node ]]> can't be shown (processed by xml parser before xsl transformation)
 |   NS6, border don't want to appears
 |
 +-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; exclude-result-prefixes="xsl">
    <xsl:output indent="yes" method="html"/>
    <!-- low priority on root node in case of include -->
    <xsl:template match="/" priority="-2">
        <html>
            <head>
                <style xml:lang="en" test="&quot;&amp;
&gt;&lt;">

            /*
            body css properties are applied to operators

            nodes have a class :
                processing-instruction, comment,
                text, attribute value
                tag name, attribute name
            tag+atts are included in el class
             */

            body
                {font-family: monospace, sans-serif; font-size: 90%;
                color:red; }
            .pi
                {color:#000080; font-weight: bold;}
            .comment
                { margin:0; padding:0.5ex;
                 font-size:100%; 
                font-family: monospace, sans-serif;
                color:#666666; background:#FFFFF5; font-weight: 100; }
            .text
                { font-size:100%; color:black; margin:0; padding:0;
                font-weight:bold; font-family:  monospace, sans-serif;
                }
            .val
                {color:black; font-family: monospace, sans-serif; font-weight:bold;}
            .tag
                {color:#000080; font-family: sans-serif; }
            .att
                {color:#0000FF; font-family: sans-serif; }

            .el, .el-toggle
                {background:#F5F5F5; white-space:nowrap; margin:0}

            /* global formatting */

            .el-toggle, .toggle
                {cursor: pointer}
            .hide, .hide *
                {text-decoration: underline;}

            /* margins could be used instead of unbreakable spaces
            .block
                {margin-left:2ex; padding-left:2ex; border-left: 1 dotted }
            */


                </style>
                <script type="text/javascript">
            // toggle node with an id, add class "hide" to the toggler
           function toggle(src, id)
           {
                if (!src.innerHTML || !src.className ) return false;
                if (!document.getElementById) return false;
                tgt=document.getElementById(id);
                if (!tgt || !tgt.style) return false;
                tgt.style.display=(tgt.style.display=='none')?'':'none';
                // change class of the toggler
                src.className=
                    (src.className.search('hide') != -1)?
                     src.className.replace(/ ?hide ?/gi, ''):
                     "hide "+src.className;
                 // close element properly
                src.innerHTML=
                    (src.innerHTML.search('/&amp;gt;') != -1)?
                     src.innerHTML.replace(/\/&amp;gt;/, '&amp;gt;'):
                     src.innerHTML.replace(/&amp;gt;/, '/&amp;gt;');
                return true;
           }

           </script>
            </head>
            <body>
                <xsl:apply-templates mode="src"/>
            </body>
        </html>
    </xsl:template>
    <!-- PI -->
    <xsl:template match="processing-instruction()" mode="src">
        <div class="pi">
            <xsl:text>&lt;?</xsl:text>
            <xsl:value-of select="name(.)"/>
            <xsl:text>&#32;</xsl:text>
            <xsl:value-of select="."/>
            <xsl:text>?></xsl:text>
        </div>
    </xsl:template>
    <!-- xmlns attributes -->
    <xsl:template name="xmlns">
        <xsl:if test=".=/*">
            <xsl:choose>
                <xsl:when xmlns:xalan="http://xml.apache.org/xalan"; test="function-available('xalan:distinct')">
                    <xsl:for-each select="xalan:distinct((//*|//@*)/namespace::*[name()!='xml'])">
                        <xsl:call-template name="att">
                            <xsl:with-param name="name" select="concat('xmlns:', name())"/>
                            <xsl:with-param name="value" select="."/>
                        </xsl:call-template>
                    </xsl:for-each>
                </xsl:when>
                <xsl:when xmlns:saxon="http://saxon.sf.net/"; test="function-available('saxon:distinct')">
                    <xsl:for-each select="saxon:distinct((//*|//@*)/namespace::*[name()!='xml'])">
                        <xsl:call-template name="att">
                            <xsl:with-param name="name" select="concat('xmlns:', name())"/>
                            <xsl:with-param name="value" select="."/>
                        </xsl:call-template>
                    </xsl:for-each>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:call-template name="distinct">
                        <xsl:with-param name="crowd" select="(//*|//@*)/namespace::*[name()!='xml']"/>
                    </xsl:call-template>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:if>
    </xsl:template>
    <!-- attribute -->
    <xsl:variable name="search-atts" select="document('')/*/xsl:template[@name='search-atts']/search"/>
    <xsl:template name="att" match="@*" mode="src">
        <xsl:param name="name" select="name()"/>
        <xsl:param name="value">
            <xsl:value-of select="."/>
        </xsl:param>
        <xsl:text>&#32;</xsl:text>
        <span class="att">
            <xsl:value-of select="$name"/>
        </span>
        <xsl:text>="</xsl:text>
        <xsl:if test="$value != ''">
            <span class="val">
                <!-- correct entities -->
                <xsl:call-template name="replaces">
                    <xsl:with-param name="string" select="$value"/>
                    <xsl:with-param name="searches" select="$search-atts"/>
                </xsl:call-template>
            </span>
        </xsl:if>
        <xsl:text>"</xsl:text>
    </xsl:template>
    <!-- find/replace to search in attributes value -->
    <xsl:template name="search-atts">
        <search>
            <find>&#xA;</find>
            <replace>
                <br/>
            </replace>
        </search>
        <!-- entities -->
        <search>
            <find>&amp;</find>
            <replace>&amp;amp;</replace>
        </search>
        <search>
            <find>&quot;</find>
            <replace>&amp;quot;</replace>
        </search>
        <search>
            <find>&gt;</find>
            <replace>&amp;gt;</replace>
        </search>
        <search>
            <find>&lt;</find>
            <replace>&amp;lt;</replace>
        </search>
    </xsl:template>
    <!--  text -->
    <xsl:template match="text()" mode="src">
        <!-- only non empty text nodes are matched -->
    </xsl:template>
    <xsl:variable name="search-text" select="document('')/*/xsl:template[@name='search-text']/search"/>
    <xsl:template match="*/text()[normalize-space(.)!='']" mode="src" priority="1">
        <span class="text">
            <xsl:call-template name="replaces">
                <xsl:with-param name="string" select="translate(., '&#32;', '&#160;')"/>
                <xsl:with-param name="searches" select="$search-text"/>
            </xsl:call-template>
        </span>
    </xsl:template>
    <!-- find/replace to search -->
    <xsl:template name="search-text">
        <search>
            <find>&#xA;</find>
            <replace>
                <br/>
            </replace>
        </search>
        <!-- entities -->
        <search>
            <find>&amp;</find>
            <replace>&amp;amp;</replace>
        </search>
        <search>
            <find>&gt;</find>
            <replace>&amp;gt;</replace>
        </search>
        <search>
            <find>&lt;</find>
            <replace>&amp;lt;</replace>
        </search>
    </xsl:template>
    <!-- comment -->
    <xsl:template match="comment()" mode="src">
        <div>
            <xsl:call-template name="margin"/>
            <span class="toggle" onclick="if(window.toggle) toggle(this, '{generate-id()}');">
                <xsl:text>&lt;!--</xsl:text>
            </span>
            <xsl:if test=". != ''">
                <span class="comment" id="{generate-id()}">
                    <!-- replace may be long -->
                     <xsl:call-template name="replaces">
                        <xsl:with-param name="string" select="translate(., '&#32;', '&#160;')"/>
                        <xsl:with-param name="searches" select="$search-text"/>
                    </xsl:call-template>
                </span>
            </xsl:if>
            <xsl:text>--></xsl:text>
        </div>
    </xsl:template>
    <!-- element empty -->
    <xsl:template match="*" mode="src">
        <div>
            <xsl:call-template name="margin"/>
            <span class="el">
                <xsl:text>&lt;</xsl:text>
                <span class="tag">
                    <xsl:value-of select="name(.)"/>
                </span>
                <xsl:call-template name="xmlns"/>
                <xsl:apply-templates select="@*" mode="src"/>
                <xsl:text>/></xsl:text>
            </span>
        </div>
    </xsl:template>
    <!-- element with text -->
    <xsl:template match="*[text()]" mode="src">
        <div>
            <xsl:call-template name="margin"/>
            <span class="el-toggle" onclick="if(window.toggle) toggle(this, '{generate-id()}');">
                <xsl:text>&lt;</xsl:text>
                <span class="tag">
                    <xsl:value-of select="name(.)"/>
                </span>
                <xsl:call-template name="xmlns"/>
                <xsl:apply-templates select="@*" mode="src"/>
                <xsl:text>></xsl:text>
            </span>
            <span id="{generate-id()}">
                <xsl:apply-templates mode="src"/>
                <span class="el">
                    <xsl:text>&lt;/</xsl:text>
                    <span class="tag">
                        <xsl:value-of select="name(.)"/>
                    </span>
                    <xsl:text>></xsl:text>
                </span>
            </span>
        </div>
    </xsl:template>
    <!-- element with children -->
    <xsl:template match="*[*]" mode="src" priority="2">
        <!-- strip it if you prefer CSS setted margin -->
        <div>
            <xsl:call-template name="margin"/>
            <span class="el-toggle" onclick="if(window.toggle) toggle(this, '{generate-id()}');">
                <xsl:text>&lt;</xsl:text>
                <span class="tag">
                    <xsl:value-of select="name(.)"/>
                </span>
                <xsl:call-template name="xmlns"/>
                <xsl:apply-templates select="@*" mode="src"/>
                <xsl:text>></xsl:text>
            </span>
        </div>
        <div id="{generate-id()}">
            <xsl:apply-templates mode="src"/>
            <!-- strip it if you prefer CSS setted margin -->
            <xsl:call-template name="margin"/>
            <span class="el">
                <xsl:text>&lt;/</xsl:text>
                <span class="tag">
                    <xsl:value-of select="name(.)"/>
                </span>
                <xsl:text>></xsl:text>
            </span>
        </div>
    </xsl:template>
    <!-- unbreakable space margin -->
    <xsl:template name="margin">
        <xsl:for-each select="ancestor::*">
            <xsl:text>&#160;&#160;&#160;&#160;</xsl:text>
        </xsl:for-each>
    </xsl:template>
    <!--
     find/replace on a set of nodes
     thanks to [EMAIL PROTECTED]
     http://www.biglist.com/lists/xsl-list/archives/200110/msg01229.html 
     fixed and adapted by [EMAIL PROTECTED] -->
    <xsl:template name="replaces">
        <xsl:param name="string"/>
        <xsl:param name="searches" select="no-node"/>
        <xsl:choose>
            <xsl:when test="false()"><!-- java replace ?? --></xsl:when>
            <xsl:otherwise>
                <xsl:variable name="first" select="$searches[1]"/>
                <xsl:variable name="rest" select="$searches[position() > 1]"/>
                <xsl:choose>
                    <xsl:when test="$first and contains($string, $first/find)">
                        <!-- replace with rest in before -->
                        <xsl:call-template name="replaces">
                            <xsl:with-param name="string" select="substring-before($string, $first/find)"/>
                            <xsl:with-param name="searches" select="$rest"/>
                        </xsl:call-template>
                        <!-- copy-of current replace -->
                        <xsl:copy-of select="$first/replace/node()"/>
                        <!-- replace with all in after -->
                        <xsl:call-template name="replaces">
                            <xsl:with-param name="string" select="substring-after($string, $first/find)"/>
                            <xsl:with-param name="searches" select="$searches"/>
                        </xsl:call-template>
                    </xsl:when>
                    <!-- empty the searches -->
                    <xsl:when test="$rest">
                        <xsl:call-template name="replaces">
                            <xsl:with-param name="string" select="$string"/>
                            <xsl:with-param name="searches" select="$rest"/>
                        </xsl:call-template>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$string"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <!--  thanks to [EMAIL PROTECTED] -->
    <xsl:template name="distinct">
        <xsl:param name="crowd"/>
        <xsl:param name="ones" select="crowd[1]"/>
        <xsl:choose>
            <xsl:when test="$crowd">
                <xsl:call-template name="distinct">
                    <xsl:with-param name="ones" select="$ones | $crowd[1][not(. = $ones )]"/>
                    <xsl:with-param name="crowd" select="$crowd[position() &gt; 1]"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:for-each select="$ones">
                    <xsl:call-template name="att">
                        <xsl:with-param name="name" select="concat('xmlns:', name())"/>
                        <xsl:with-param name="value" select="."/>
                    </xsl:call-template>
                </xsl:for-each>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to