RE: [xsl] substitute &#13; with <br/>

Subject: RE: [xsl] substitute &#13; with <br/>
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Thu, 7 Aug 2003 17:01:55 +0100
> Hello Andrew,
> Andrew Welch wrote:
> >> Hello Alexander,
> >>
> >> this is probably a FAQ. It's also an XML topic not an XSLT one.
> >>
> >> Look to 2.11 "End-Of-Line Handling" in the XML spec.
> >
> >No, it's an html issue.  Carriage returns are normalised to a single
> >space (I think) so to recreate their behaviour you need to use <br />
> ><div /> <p /> etc.
> No, the original issue is clearly an XML one, as he wrote:
>    "I thought of doing it with entities in the source XML
>     like <!ENTITY #13 "<br/>">, but that doesn't work."

But why was he trying to replace &_#13; with <br />?   Because in html
&_#13; doesn't cause a carriage return, a <br /> does.  He could learn
all of the possible line endings in xml and still not have the answer.

> >I think your best plan of action is to modify your xml to replace
> >with <br /> (Im assuming that as you can insert entities this
> >be too much trouble).
> This was exactly what Alexander was trying, without success. (or do
> you mean: manually, with a text editor?)

Inserting entity declarations is not the same as replacing &_#13; with
<br /> with some tool... How would the parser distinguish between &_#13;
the character reference and &_#13; the entity?  

> >If however that breaks a DTD or is not possible, you will have to use
> >recursive named template that gets called from you text() matching
> >template.  This can then use substring-before() and substring-after()
> >recursively replace what you need.
> &_#13; cannot be matched or replaced with XSLT functions, as it has
> been deleted by the XML parser.

Yeah it can - it hasn't been deleted by the parser, its just been
resolved.  You can still check if a string contains it, just like you
can check if a string contains &_#120; (the letter 'x').

As DC always says 'the reference and the character are one and the same
thing' - you could write your entire xml file in character references
(if you were mad). 

As long as you cover all your bases with all possible line endings
(iirc, the parser can choose which kind of line ending to produce, but
theres still only a few) then a recursive template is the usual

Or for performance, if you were using java you could write a sax filter
that coverted the value on its way into the trasform, then write a
template to deal with whatever you has converted line endings to.

Or, of course, to save all the hassle just wrap the text that contains
the line endings in html's <pre>...</pre> which will render the text as
is (if it fits your needs).


 XSL-List info and archive:

Current Thread