[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: xml nodes with spaces (at start, end, or just spac

Subject: RE: xml nodes with spaces (at start, end, or just spaces) n ot showing correctly with xsl
From: Pieter Reint Siegers Kort <pieter.siegers@xxxxxxxxxxx>
Date: Wed, 16 Jun 2004 08:49:18 -0500
xml nodes spaces
Hi Andrew,

The following xslt may help you:

<?xml version='1.0' ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

	<xsl:output method="xml" indent="yes" />

	<xsl:template match="node()|@*">
		<xsl:copy>
			<xsl:apply-templates select="node()|@*"/>
		</xsl:copy>
	</xsl:template>

	<xsl:template match="inserted" >
		<xsl:text> </xsl:text>
	</xsl:template>

	<xsl:template match="deleted" >
		<xsl:text> </xsl:text>
	</xsl:template>

</xsl:stylesheet>

It outputs:
<?xml version="1.0" encoding="UTF-16"?>
<Text>The quick  brown fox jumped over the lazy  dog.</Text>

You will however retain spaces that were already there (that's why you now
get two spaces before the words 'brown' and 'dog').

HTH,
<prs/>

-----Original Message-----
From: Andrew Madigan [mailto:Andrew_Madigan@xxxxxxxxxxxxx] 
Sent: Wednesday, June 16, 2004 2:47 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  xml nodes with spaces (at start, end, or just spaces) not
showing correctly with xsl

Hi,
I am trying to display xml that has formatting and also has a form of 'track
changes' in a browser using xsl.
The 'track changes' is implemented by using <inserted> and <deleted> tags to
identify changes (these are escaped with &lt; &gt; etc. in the XML).
I want to display the latest version of the content so I show insertions and
do not show deletions.

Sample XML (snippet):
<Text>The&lt;inserted&gt; &lt;/inserted&gt;quick&lt;deleted&gt;
&lt;/deleted&gt; brown fox&lt;inserted&gt;
&lt;/inserted&gt;jumped&lt;inserted&gt; &lt;/inserted&gt;over the
lazy&lt;deleted&gt; &lt;/deleted&gt; dog.</Text>



....which without the escaping becomes: 
<Text>The<inserted> </inserted>quick<deleted> </deleted> brown fox<inserted>
</inserted>jumped<inserted> </inserted>over the lazy<deleted> </deleted>
dog.</Text>



So I am trying to get this to show as "The quick brown fox jumped over the
lazy dog."

Sample XSL 1 (snippet):
<xsl:template match="deleted"/>
 <xsl:template match="inserted">
   <xsl:apply-templates/>
 </xsl:template>
<xsl:template match="br">
   <br/>
   <xsl:apply-templates/>
 </xsl:template>
  <xsl:template match="i">
  <i>
  <xsl:apply-templates/>
  </i>
 </xsl:template>
<xsl:template match="b">
 <b>
 <xsl:apply-templates/>
 </b>
 </xsl:template>



Sample XML 2 (snippet):
<xsl:template match="deleted"/>
   <xsl:template match="inserted">
   <xsl:copy-of-select='.'/>
 </xsl:template>
    <xsl:template match="br">
   <br/>
   <xsl:apply-templates/>
 </xsl:template>
  <xsl:template match="i">
  <i>
  <xsl:apply-templates/>
  </i>
 </xsl:template>
<xsl:template match="b">
 <b>
 <xsl:apply-templates/>
 </b>
 </xsl:template>


I have tried both of these solutions and neither work. I need to be able to
have formatting inside the insertions - hence the attempt to use
<xsl:apply-templates/>.
The output I am getting is "Thequick brown foxjumpedover the lazy dog."
- as though the spaces were never inserted.

Thanks in advance for any help or suggestions.

Andy



--+------------------------------------------------------------------
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@xxxxxxxxxxxxxxxxxxxxxx>
--+--

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.