xsl-list
[Top] [All Lists]

Re: [xsl] Search and Replace Help

2007-05-20 07:27:27
First off, thanks for the reply, I learned quite a bit.  And now, because of
that, I can refine my question a bit.

The XML is output from vBulletin as is when someone downloads their Private
Messages, I can't change that.  My intention is to create an XSLT to format
the output so that it is easier for users to read instead of them just
looking at the raw XML.  Because of that, my intent is for this to be viewed
in a normal web browsers (I am using FF 2.0 for this).

1) Thanks for explaining the <![CDATA[]] tag to me, that explains why I see
the <br /> tag instead of it doing what I expected it to.  Is there some way
to get the same effect as an XHTML/HTML <br /> within a <![CDATA[]] element?
The search replace template that I found is replacing any linefeeds it finds
with the <br />, but even with just the linefeeds it doesn't actually do a
linefeed.

2) I'll keep looking around for a way to replace [QUOTE=name] [/QUOTE] with
the correct XHTML/HTML, but unless I find a way around the <![CDATA[]]
limitation, it won't matter.

Thanks for the help so far, this is fun.


On 5/20/07 9:59 AM, "cknell(_at_)onebox(_dot_)com" 
<cknell(_at_)onebox(_dot_)com> wrote:

It seems that the list is very quiet on the weekends.

First, "[quote=name]...[/quote]" is not XML. So it is unreasonable to expect
to be able to use XSLT to do anything with them except reproduce it as is or
operate on it with string methods.

You have a "message" element. It appears between the opening and closing
(<message></message>) tags.

The entire content of the message element is enclosed in <![CDATA[]]>. This is
an instruction to the XSLT processor to treat the enclosed bytes as text, not
markup. As far as the stylesheet is concerned, there is no structure between
<![CDATA[ and ]]>, it's just a collection of bytes.

There is some evidence that you are working in this way, but since you say
that you are new to XSLT, and since it is a frequent error by newcomers to
assume that because they see a structure inside the <![CDATA[]]> tag, that the
XSLT processor must therefore also see it.

So, on to your specific complaints.
==========================
1) it is writing out/displaying <br /> instead
of doing a line break

You are getting a break element (<br/>) because that's what you told the
stylesheet to output:
e.g.,
<xsl:text>To: </xsl:text> <xsl:value-of select="touser"/><br />

What constitutes a "line break" depends on what your platform is. In an HTML
browser, the "<br/>" element is a line break. In Windows, you need a carriage
return character and a linefeed character. In Linux/Unix you need only the
linefeed, on the Mac OS (up to version 9), it was only the carriage return.

If you could identify what your target is (apparently not an HTML browser) you
could instruct the XSLT processor to output the ASCII character or characters
to produce a newline by inserting that/those characters in the stylesheet
where you now have the <br/> element.

The linefeed is & #10; and the carriage return is & #13; (I've inserted a
space between the ampersand and the # to prevent any possible literal
interpretation by your mail reader as instructions. When you use them in your
stylesheet, be sure that no space appears there.

2) I need to replace [QUOTE=jack] & [QUOTE=john]
with <blockquote><i>Originally posted by: <b>jack (or john)</b></i> (while
allowing for the fact that there may be a mary, jake, etc.) and [/QUOTE]
with </blockquote>.

As I said earlier, this is not XML markup and XSLT templates won't process
them as if it were. If you are using an XSLT 2.0 processor, you could use the
regex functions to process this string data and create the elements.
Alternatively, you could use Java or perl or C# or C or VB (well, you get the
idea) to create a pre-processor that would create the elements before you fed
it into the stylesheet.




--~------------------------------------------------------------------
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>
--~--