|
Subject: RE: [xsl] why no indent here From: "Tony Graham" <tgraham@xxxxxxxxxx> Date: Mon, 12 Dec 2011 09:12:13 -0000 (GMT) |
On Mon, December 12, 2011 8:42 am, Roelof Wobben wrote:
...
>> > <body>Naam : Tamara Wobben
>> > Geboorte gewicht : 2000 gram
>> > Geboorte lengte : 44 cm.
>> > Geboortedatum : 1 september 2005
>> >
>> > </body>
...
> and in the xhtml there are no <br> tags so to my knowlegde the linebreaks
> are not there.
I wouldn't expect there to be, but I would expect that the line breaks in
the original would be there if you did viewed 'Page Source' in your web
browser or opened the XHTML in a text editor.
>> You could output the content in a <pre>, though by default that would
>> come
>> out as monospaced text. You could then add CSS styles to use a
>> proportionally-spaced font with the <pre> if that's what you want.
>>
>> If you were using XSLT 2.0, you could use xsl:analyse-string to replace
>> the line breaks with <br /> elements. With XSLT 1.0, you could do much
>> the same thing with a recursive template that uses substring-before() to
>> find the text before the first line break, outputs that text and a <br
>> />,
>> then calls itself with the substring-after() the first line break. When
>> there's no more line breaks, the template would just output the
>> remaining
>> text.
>
> Oke, then I have to find or write myself such a recursive template that do
> that. Symphomny works with xslt 1.0
Neither approach is all that difficult, and the choice probably depends on
whether you need to show the indent of the second and subsequent lines:
---------------------------------
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<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="body">
<div>
<pre style="font-family: serif">
<xsl:apply-templates />
</pre>
<p>
<xsl:call-template name="add-br" />
</p>
</div>
</xsl:template>
<xsl:template name="add-br">
<xsl:param name="text" select="." />
<xsl:choose>
<xsl:when test="contains($text, ' ')">
<xsl:value-of select="substring-before($text, ' ')" />
<br />
<xsl:text> </xsl:text>
<xsl:call-template name="add-br">
<xsl:with-param name="text" select="substring-after($text, ' ')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
-----------------------------------------
produces:
-----------------------------------------
<!DOCTYPE div PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<div>
<pre style="font-family: serif">Naam : Tamara Wobben
Geboorte gewicht : 2000 gram
Geboorte lengte : 44 cm.
Geboortedatum : 1 september 2005
</pre>
<p>Naam : Tamara Wobben <br />
Geboorte gewicht : 2000 gram <br />
Geboorte lengte : 44 cm. <br />
Geboortedatum : 1 september 2005<br />
<br />
</p>
</div>
-------------------------------------------
Regards,
Tony Graham tgraham@xxxxxxxxxx
Consultant http://www.mentea.net
Mentea 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
XML, XSL-FO and XSLT consulting, training and programming
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] What problem are you tryi, Wendell Piez | Thread | RE: [xsl] why no indent here, Scott Trenda |
| Re: [xsl] why no indent here, Wolfgang Laun | Date | Re: [xsl] why no indent here, Michael Kay |
| Month |