xsl-list
[Top] [All Lists]

RE: Re: outputing tags

2003-01-06 03:25:42
I am curious to know how others handle a situation I discribed
above.  I believe that I am going to run into this problem in
many places and would like to know the best solution.  Or at
least the auther of the replies best solution.

I do NOT feel that relying on the tradition linebreak is a
good idea.  I figured the best thing to do is denote a line
break in my XML the same way HTML denotes a line break.
Espically considering the target output is HTML.

If you are using a text editor to edit your XML files you might want to use a 
line-feed.

The details about line break handling in XML from the specification
http://www.w3.org/TR/1998/REC-xml-19980210#sec-line-ends
2.11 End-of-Line Handling

XML parsed entities are often stored in computer files which, for editing 
convenience, are organized into lines. These lines are typically separated by 
some combination of the characters carriage-return (#xD) and line-feed (#xA).

To simplify the tasks of applications, wherever an external parsed entity or 
the literal entity value of an internal parsed entity contains either the 
literal two-character sequence "#xD#xA" or a standalone literal #xD, an XML 
processor must pass to the application the single character #xA. (This behavior 
can conveniently be produced by normalizing all line breaks to #xA on input, 
before parsing.) 


This is how you would convert a line-feed characters to <br/>.  If you do this 
you will need to be careful not to have nodes that contain only line-feed 
because they will be removed by the xml parser before it gets to be processed.

<?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" version="1.0" encoding="UTF-8" indent="yes"/>
        <xsl:template match="text()[contains(.,'&#xA;')]">
                <xsl:value-of 
select="substring-before(.,'&#xA;')"/><br/><xsl:value-of 
select="substring-after(.,'&#xA;')"/>
        </xsl:template>
</xsl:stylesheet>

Edward Middleton

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



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