Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   XML/XSL HTML problem (http://www.velocityreviews.com/forums/t168467-xml-xsl-html-problem.html)

ChrisEvans 12-24-2004 02:57 PM

XML/XSL HTML problem
 
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


Martin Honnen 12-24-2004 03:08 PM

Re: XML/XSL HTML problem
 


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/

Luke Dalessandro 12-24-2004 03:24 PM

Re: XML/XSL HTML problem
 
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

ChrisEvans 12-24-2004 03:32 PM

Re: XML/XSL HTML problem
 
Hi there,
Brilliant. looks like what I'm after! :-) Thanks.


ChrisEvans 12-24-2004 04:04 PM

Re: XML/XSL HTML problem
 
Hi there,
Brilliant. looks like what I'm after! :-) Thanks.


ChrisEvans 12-24-2004 04:06 PM

Re: XML/XSL HTML problem
 
Hi there,
Brilliant. looks like what I'm after! :-) Thanks.



All times are GMT. The time now is 07:23 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.