Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Maintaining spaces with xsl transformation of xml

Status
Not open for further replies.

newbie404

Programmer
Mar 2, 2004
19
IE
Hi,

I have some trouble getting my xml to display correctly using xsl. I have a node with formatting which can also contain changes which are marked <insertion> or <deletion>. Insertions should be shown, deletions should not.

A sample piece of this xml is:

<Text> text&lt;inserted&gt; &lt;/inserted&gt;&lt;b&gt;te&lt;/b&gt;xt</Text>

<Text>this is added withb&lt;b&gt;old &lt;br/&gt;&lt;br/&gt;&lt;/b&gt;&lt;b&gt;&lt;i&gt;bold italic&lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;br/&gt;&lt;br/&gt;&lt;/b&gt;&lt;font face='Courier New, Courier, mono'&gt;&lt;i&gt;courier italic&lt;br/&gt;&lt;br/&gt;&lt;/i&gt;&lt;/font&gt;&lt;font face='Courier New, Courier, mono'&gt;&lt;b&gt;courier bold&lt;br/&gt;&lt;br/&gt;&lt;/b&gt;&lt;/font&gt;&lt;i&gt;italic&lt;br/&gt;&lt;br/&gt;&lt;/i&gt;&lt;font face='Courier New, Courier, mono'&gt;courier on its own&lt;/font&gt;&lt;i&gt;&lt;br/&gt;&lt;br/&gt;&lt;/i&gt;and normal text</Text>


The first node above has a space inserted between the two words "text" and the second has lots of insertions and deletions with formatting.

I find that when I use

<xsl:template match="inserted">
<xsl:value-of select="."/>
</xsl:template>

I get the spaces, but not the formatting, whereas when I use

<xsl:template match="inserted">
<xsl:apply-templates/>
</xsl:template>

I get the formatting but not the spaces. Note: the formatting is put in by also having
<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>

in my xsl.


My question is - how can I get the content to show both, while still not showing any deleted text, which I have currently working through

<xsl:template match="deleted"/>

in the xsl.


Any help or pointers are greatly appreciated!

thanks
A
 
XML:
Code:
<Article>
	<Text> text<inserted> </inserted>
		<b>te</b>xt</Text>
	<Text>this is added with b<b>old <br/>
			<br/>
		</b>
		<b>
			<i>bold italic</i>
		</b>
		<b>
			<br/>
			<br/>
		</b>
		<font face="Courier New, Courier, mono">
			<i>courier italic<br/>
				<br/>
			</i>
		</font>
		<font face="Courier New, Courier, mono">
			<b>courier bold<br/>
				<br/>
			</b>
		</font>
		<i>italic<br/>
			<br/>
		</i>
		<font face="Courier New, Courier, mono">courier on its own</font>
		<i>
			<br/>
			<br/>
		</i>and normal text</Text>
</Article>

XSL:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>

	<xsl:template match="/">
		<html>
			<head>
				<title>TEST</title>
			</head>
			<body><xsl:apply-templates/></body>
		</html>
	</xsl:template>

	<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>
	
	<xsl:template match="font">
		<font style="{@face}"><xsl:apply-templates/></font>
	</xsl:template>

</xsl:stylesheet>

HTML:
Code:
<html>
<head>
<title>TEST</title>
</head>
<body>
	 text 
		<b>te</b>xt
	this is added with b<b>old <br/>
			<br/>
		</b>
		<b>
			<i>bold italic</i>
		</b>
		<b>
			<br/>
			<br/>
		</b>
		<font style="Courier New, Courier, mono">
			<i>courier italic<br/>
				<br/>
			</i>
		</font>
		<font style="Courier New, Courier, mono">
			<b>courier bold<br/>
				<br/>
			</b>
		</font>
		<i>italic<br/>
			<br/>
		</i>
		<font style="Courier New, Courier, mono">courier on its own</font>
		<i>
			<br/>
			<br/>
		</i>and normal text
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top