XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old March 17th, 2008, 04:51 PM
nachnach's Avatar
nachnach nachnach is offline
<?php print_f(); ?>
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: London
Posts: 1,281 nachnach User rank is Sergeant Major (2000 - 5000 Reputation Level)nachnach User rank is Sergeant Major (2000 - 5000 Reputation Level)nachnach User rank is Sergeant Major (2000 - 5000 Reputation Level)nachnach User rank is Sergeant Major (2000 - 5000 Reputation Level)nachnach User rank is Sergeant Major (2000 - 5000 Reputation Level)nachnach User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 1 h 7 m 48 sec
Reputation Power: 31
Send a message via Skype to nachnach
Xsl text formatting

Ok, I've tried to fix this, but I am having no luck.
Basically, I have an XML document which contains details of an article, so as you can imagine there's allot of text in some of the XML documents.

Well, the problem I am having is, the text in the XML document is separated with lines breaks and no <br /> tags.
So, when I view the article with the XSL document, it comes out as one big lump of text.
How can I fix this?

This is the current (test) XSL, the XML and XSL are joined together via javasscript on the fly.

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
	<h1><xsl:value-of select="articles/article/title"/></h1>
	<p><xsl:value-of select="articles/article/subtitle"/></p>
	<p><xsl:value-of select="articles/article/body"/></p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Reply With Quote
  #2  
Old March 20th, 2008, 08:29 PM
nachnach's Avatar
nachnach nachnach is offline
<?php print_f(); ?>
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: London
Posts: 1,281 nachnach User rank is Sergeant Major (2000 - 5000 Reputation Level)nachnach User rank is Sergeant Major (2000 - 5000 Reputation Level)nachnach User rank is Sergeant Major (2000 - 5000 Reputation Level)nachnach User rank is Sergeant Major (2000 - 5000 Reputation Level)nachnach User rank is Sergeant Major (2000 - 5000 Reputation Level)nachnach User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 1 h 7 m 48 sec
Reputation Power: 31
Send a message via Skype to nachnach
Mmmmmm no one know how to do this?
I done some more research on this and I came across a few templates that help, but the problem now is, even though the article is displayed in Internet Explorer, it doesn't want to work in FireFox because disable-output-escaping doesn't work on that.

The fix that was meant to work, didn't.
Any help would be much appreciated.

Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="articles/article">
        <html>
			<head>
				<InvalidTag type="text/javascript" src="/scripts/disableOutputEscaping.js" />
			</head>
            <body onload="go_decoding();">
				<!-- Fix disable-output-escaping for FireFox -->
				<div id="cometestme" style="display:none;">
					<xsl:text disable-output-escaping="yes">&</xsl:text>
				</div>
				
                <xsl:choose>
                    <!-- Display insert/update date -->
                    <xsl:when test="updated_date !='' ">
                        <p align="right" style="color:#000000;">Updated on <xsl:value-of select="updated_date"/></p>
                    </xsl:when>
                    <xsl:otherwise>
                        <p align="right" style="color:#000000;">Added on <xsl:value-of select="insert_date"/></p>
                    </xsl:otherwise>
                </xsl:choose>
				
				
                <!-- Display user name -->
                <p align="right" style="color:#000000;">By <xsl:value-of select="user/name"/></p>
				
				
                <!-- Display article body -->
				<h1 style="color:#000000;">
					<xsl:value-of select="title" disable-output-escaping="yes"/>
				</h1>
				<h2 style="color:#000000;">
					<xsl:value-of select="subtitle" disable-output-escaping="yes"/>
				</h2>
				
				
				<!-- Change invalid chars -->
				<xsl:variable name="apos">'</xsl:variable>
				<xsl:variable name="value">
				    <xsl:call-template name="stringreplace">
	                    <xsl:with-param name="stringvalue" select="body"/>
	                    <xsl:with-param name="from" select="'
'"/>
	                    <xsl:with-param name="to" select="'<br/>'"/>
	                </xsl:call-template>
				</xsl:variable>
				<xsl:variable name="value2">
				    <xsl:call-template name="stringreplace">
	                    <xsl:with-param name="stringvalue" select="$value"/>
	                    <xsl:with-param name="from" select="''"/>
	                    <xsl:with-param name="to" select="''"/>
	                </xsl:call-template>
				</xsl:variable>
                
				
				<div name="decodeable">
					<p style="color:#000000;">
						<xsl:value-of select="$value2" disable-output-escaping="yes"/>
					</p>
				</div>
            </body>
        </html>
    </xsl:template>
	
	
	<!-- String replace function -->
	<xsl:template name="stringreplace">
		<xsl:param name="stringvalue"/>
		<xsl:param name="from"/>
		<xsl:param name="to"/>
		<xsl:choose>
			<xsl:when test="contains($stringvalue, $from)">
				<xsl:value-of select="substring-before($stringvalue, $from)" disable-output-escaping="yes"/>
				<xsl:if test="contains(substring($stringvalue, 1, string-length($stringvalue) - 1), $from)">
					<xsl:value-of select="$to" disable-output-escaping="yes"/>
					<xsl:call-template name="stringreplace">
						<xsl:with-param name="stringvalue" select="substring-after($stringvalue, $from)"/>
						<xsl:with-param name="from" select="$from"/>
						<xsl:with-param name="to" select="$to"/>
					</xsl:call-template>
				</xsl:if>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$stringvalue" disable-output-escaping="yes"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	
	<!-- NewLines to <br /> -->
    <xsl:template name="break">
        <xsl:param name="text"/>
        <xsl:choose>
            <xsl:when test="contains($text, '
')">
                <xsl:value-of select="substring-before($text, '
')" disable-output-escaping="yes"/>
                <br />
                <xsl:call-template name="break">
                    <xsl:with-param name="text" select="substring-after($text, '
')"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$text" disable-output-escaping="yes"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Xsl text formatting


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway