xsl-list
[Top] [All Lists]

RE: [xsl] why no indent here

2011-12-12 06:25:52

I found a answer here 
(http://www.dpawson.co.uk/xsl/sect2/N7240.html#d10122e376) but it seems no to 
work here.

 

So I have this xslt :

 



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output 
     method=" xml"  
     doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"  
     doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"; 
     omit-xml-declaration="yes" 
     encoding="UTF-8"  
     indent="yes" />

<xsl:template match="/">
     <xsl:apply-templates select="data/params" mode="top" />
     <body>
             <div id="outer">
                 <div id="container">
                     <div id="search">
                         <form method="get" id="searchform" 
action="http://www.notepadchaos.com/";>
                             <input type="text" value="" name="s" id="s" 
class="txtField" />
                             <input type="submit" id="searchsubmit" 
class="btnSearch" value="Find It " />
                        </form>
                     </div>
                         <div id="title">
                             <h2><xsl:text>Tamara Wobben</xsl:text></h2>
                        </div>
                     </div>
                     <div id="content">
                        <div class="col01">
                             <xsl:apply-templates select="data/section/entry" />
                         </div>
                         <div class="side-columns">
                             <div class="col02">
                                 <div class="pages">
                                     <!-- hier komen de losse pagina's -->
                                 </div>
                                 <div class="categories">
                                    <!-- hier komt het menu  -->
                                </div>
                             </div>
                             <div class ="col03"> 
                                <!-- hier komen de recente posts -->
                            </div>
                         </div>
                     </div>                                
                </div>              
            </body>            
</xsl:template>

<xsl:template match="data/params" mode="top"  >
  <head>
        <title>
           <xsl:value-of select="root"/>
       </title>
       <link rel="stylesheet" 
href="http://www.notepadchaos.com/wp-content/themes/notepad-chaos-v2/style.css"; 
type="text/css" media="screen" />
     </head>
</xsl:template>

<xsl:template match="section/entry">
     <div class="post">
        <h3><xsl:value-of select="title"/> </h3>
             <div class="post-inner">
                 <xsl:apply-templates select="data/section/entry/body/text()" />
         </div>
     </div>       
</xsl:template>

<xsl:template match="body//text()">
    <xsl:call-template name="make-verbatim">
       <xsl:with-param name="text" select="."/>
     </xsl:call-template>
   </xsl:template>
   
   <xsl:template name="make-verbatim">
     <xsl:param name="text" select="''"/>
   
     <xsl:variable name="starts-with-space"
                   select="substring($text, 1, 1) = ' '"/>
   
     <xsl:variable name="starts-with-nl"
                   select="substring($text, 1, 1) = '&#xA;'"/>
   
     <xsl:variable name="before-space">
       <xsl:if test="contains($text, ' ')">
         <xsl:value-of select="substring-before($text, ' ')"/>
       </xsl:if>
     </xsl:variable>
   
     <xsl:variable name="before-nl">
       <xsl:if test="contains($text, '&#xA;')">
         <xsl:value-of 
   select="substring-before($text, '&#xA;')"/>
       </xsl:if>
     </xsl:variable>
   
     <xsl:choose>
       <xsl:when test="$starts-with-space">
         <xsl:text>&#160;</xsl:text>
         <xsl:call-template name="make-verbatim">
           <xsl:with-param name="text" 
   select="substring($text,2)"/>
         </xsl:call-template>
       </xsl:when>
   
       <xsl:when test="$starts-with-nl">
         <br/><xsl:text>&#xA;</xsl:text>
         <xsl:call-template name="make-verbatim">
           <xsl:with-param name="text" 
   select="substring($text,2)"/>
         </xsl:call-template>
       </xsl:when>
   
       <!-- if the string before a space 
   is shorter than the string before
            a newline, fix the space...-->
       <xsl:when test="$before-space != ''
                       and ((string-length($before-space)
                             &lt; string-length($before-nl))
                             or $before-nl = '')">
         <xsl:value-of select="$before-space"/>
         <xsl:text>&#160;</xsl:text>
         <xsl:call-template name="make-verbatim">
           <xsl:with-param name="text"
   select="substring-after($text, ' ')"/>
         </xsl:call-template>
       </xsl:when>
   
       <!-- if the string before a newline 
   is shorter than the string before
            a space, fix the newline...-->
       <xsl:when test="$before-nl != ''
                       and ((string-length($before-nl)
                             &lt; string-length($before-space))
                             or $before-space = '')">
         <xsl:value-of select="$before-nl"/>
         <br/><xsl:text>&#xA;</xsl:text>
         <xsl:call-template name="make-verbatim">
           <xsl:with-param name="text" 
   select="substring-after($text, '&#xA;')"/>
         </xsl:call-template>
       </xsl:when>
   
       <!-- the string before the newline and the string before the
            space are the same; which means they must both be empty -->
       <xsl:otherwise>
         <xsl:value-of select="$text"/>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:template>


</xsl:stylesheet>

 

 

And this is my full xml : 

 


<?xml version="1.0" encoding="utf-8" ?>
<data>
<params>
<today>2011-12-09</today>
<current-time>13:22</current-time>
<this-year>2011</this-year> 
<this-month>12</this-month>
<this-day>09</this-day>
<timezone>+01:00</timezone> 
<website-name>Tamara Wobben</website-name> 
<page-title>Home</page-title> 
<root>http://test.tamarawobben.nl</root>
<workspace>http://test.tamarawobben.nl/workspace</workspace> 
<root-page>home</root-page>
<current-page>home</current-page> 
<current-page-id>4</current-page-id>
<current-path>/home/?debug&amp;symphony-page=home/</current-path> 
<parent-path>/</parent-path>
<current-url>http://test.tamarawobben.nl/home/?debug&amp;symphony-page=home/</current-url>
<upload-limit>2097152</upload-limit>
<symphony-version>2.2.5</symphony-version>
<cookie-username>admin</cookie-username> 
<cookie-pass>bd619be1eb114dce7512fc0c5af1487c58074ab4</cookie-pass>
<site-mode>live</site-mode>
<ds-section>
<item handle="1">&lt;span class=&quot;order&quot;&gt;1&lt;/span&gt;</item> 
</ds-section>
</params> 
<events /> 
<section>
<section id="6" handle="sections">Sections</section> 
<entry id="9"> 
 <title handle="even-voorstellen">Even voorstellen</title>
 <body>Naam : Tamara Wobben 
         Geboorte gewicht : 2000 gram 
         Geboorte lengte : 44 cm. 
         Geboortedatum : 1 september 2005
    </body>
 </entry> 
 </section> 
 </data>

 

 

But no not a single character is shown. 

 

Roelof


----------------------------------------
Date: Mon, 12 Dec 2011 09:15:56 +0000
From: mike(_at_)saxonica(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] why no indent here

So I can't preserve the linebreaks in the xml file into the html file ?

If you do "view source" you'll see that the line breaks are indeed
present in your HTML. The problem is that line breaks in HTML aren't
displayed as line breaks by the browser. To get a line break in the
browser output, you need a <br> element in the HTML.

The question "how do I convert linebreaks into <br> elements" is FAQ
and you should be able to find an answer by googling.

Michael Kay
Saxonica

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
                                        
--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>