Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XML/XSL HTML problem

Reply
Thread Tools

XML/XSL HTML problem

 
 
ChrisEvans
Guest
Posts: n/a
 
      12-24-2004
Hi there,
I've got an XML file which uses an XSL stylesheet. Problem is:

<br />

tags don't work for me when the content is gathered from the xml.
Example:

<main>
<title>Hi</title>
<content>Hello, how are you?<br /><br />I'm fine.</content>
</main>

Then in the stylesheet its positioned in the correct place etc and
using <xsl:value-of select="content" /> - trouble is the <br /> doesn't
do anything.

Help would be appreciated!

Thanks,

Chris

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      12-24-2004


ChrisEvans wrote:


> I've got an XML file which uses an XSL stylesheet. Problem is:
>
> <br />
>
> tags don't work for me when the content is gathered from the xml.
> Example:
>
> <main>
> <title>Hi</title>
> <content>Hello, how are you?<br /><br />I'm fine.</content>
> </main>
>
> Then in the stylesheet its positioned in the correct place etc and
> using <xsl:value-of select="content" /> - trouble is the <br /> doesn't
> do anything.


<xsl:value-of select="content" /> outputs the string value of the
element <content>, if the element has empty child elements like <br />
then these indeed do not in any way show up with value-of.
What you probably want is recursive processing of child nodes of
<content> e.g.
<xsl:template match="content">
<div>
<xsl:apply-templates />
</div>
</xsl:template>
and then a template that copies <br> elements from the input XML to the
XSLT output
<xsl:template match="br">
<xsl:copy />
</xsl:template>

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Luke Dalessandro
Guest
Posts: n/a
 
      12-24-2004
Martin Honnen wrote:
>
>
> ChrisEvans wrote:
>
>
>> I've got an XML file which uses an XSL stylesheet. Problem is:
>>
>> <br />
>>
>> tags don't work for me when the content is gathered from the xml.
>> Example:
>>
>> <main>
>> <title>Hi</title>
>> <content>Hello, how are you?<br /><br />I'm fine.</content>
>> </main>
>>
>> Then in the stylesheet its positioned in the correct place etc and
>> using <xsl:value-of select="content" /> - trouble is the <br /> doesn't
>> do anything.

>
>
> <xsl:value-of select="content" /> outputs the string value of the
> element <content>, if the element has empty child elements like <br />
> then these indeed do not in any way show up with value-of.
> What you probably want is recursive processing of child nodes of
> <content> e.g.
> <xsl:template match="content">
> <div>
> <xsl:apply-templates />
> </div>
> </xsl:template>
> and then a template that copies <br> elements from the input XML to the
> XSLT output
> <xsl:template match="br">
> <xsl:copy />
> </xsl:template>
>


Logically the next thing you are going to run into is transforming
something like

<a href="somewhere">somewhere</a>

from your xml (at least I did). You use the same construct as Martin,
but instead of just copying the tag and applying templates to its
content, you need to copy the attributes as well.

<xsl:template match="a">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>

Then, you are going to start accumulating a list of all of these types
of standard html markup that you want to allow in your xml (like style
etc...) and you are going to wind up with tons of these simple template
matches and think to yourself, "there must be an easier way to do this,"
and there is.

<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>

Will match and copy ALL UNSPECIFIED TAGS, and their attributes, in your
xml. By unspecified I mean anything that you haven't explicitely written
a template for.

Hope this helps... it just looked like you were on the same path as I
was, and it took me lots of pain to figure this simple stuff out. Good luck.

Luke
 
Reply With Quote
 
ChrisEvans
Guest
Posts: n/a
 
      12-24-2004
Hi there,
Brilliant. looks like what I'm after! Thanks.

 
Reply With Quote
 
ChrisEvans
Guest
Posts: n/a
 
      12-24-2004
Hi there,
Brilliant. looks like what I'm after! Thanks.

 
Reply With Quote
 
ChrisEvans
Guest
Posts: n/a
 
      12-24-2004
Hi there,
Brilliant. looks like what I'm after! Thanks.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
firefox html, my downloaded html and firebug html different? Adam Akhtar Ruby 9 08-16-2008 07:55 PM
problem with index.html .(page is automatically gettin redirected to index.html) karthikeyavenkat Java 2 03-17-2005 10:01 PM
How do I identify word<html><html>other word? Laura Perl 1 06-04-2004 11:32 PM
how to redirect to a frames-based html page and load the right html when coming from an ASP.NET page Mark Kamoski ASP .Net 1 08-13-2003 05:51 AM
How to use HTML::Parser to remove HTML tags and print result Mitchua Perl 1 07-15-2003 02:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57