|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Newbie to XML/XSLT/Whitespace problems
Hi, I am trying out some xml/xslt stuff for a new procedure manual type database. Basically, I have an access database with some memo fields where users type in instructions. These can have multiple parts so they use spaces or tabs to indent certain pieces of text. When generate my xml to display it, all of the indentation is there in the xml. When I transform it via XLST style sheet all of the formatting is gone. For example :- This proc has two parts :- 1. Start 2. End Comes out as :- This proc has two parts 1. Start 2. End I've tried "preserve-space" to no avail - is there a way of keeping this nice formatting the users have painstakingly input ?????????? Meant to say also that I generate all XML via MSXML and VBA from within the access d/b. XSL Style sheet typed up by hand. Cheers |
|
#2
|
||||
|
||||
|
Try enclosing your text in <![CDATA[ ]]> tags:
Code:
<xml_tag><![CDATA[multi-line text goes here]]></xml_tag>
__________________
# Jeremy Explain your problem instead of asking how to do what you decided was the solution. |
|
#3
|
|||
|
|||
|
Many thanks for the post and I can understand the theory behind it.
So, OK, coded that into the source xml document manually without worrying about how to do it via VBA for the moment and I can see that it groups the multi-line text together if I open it without the XSLT stylesheet. However, when I put the xslt stylesheet in, the formatting disappears. I am using Jeni Tennison's book (amongst others) and have an <xsl utput> element in my XSLT stylesheet as well in an attempt to solve the problem - but all to no avail. I've tried with this element in and with it out as well. Do you have any other suggestions I could try out ? This is rapidly sapping my confidence in XML/XSLT as something I want to introduce into our organisation !!!!!!!!!!! |
|
#4
|
||||
|
||||
|
Sorry, CDATA was not the correct suggestion.
Whitespace is one of those XML / XSLT quirks. I searched Google for "xml whitespace" and came up with several examples and articles on how to deal with whitespace. |
|
#5
|
|||
|
|||
|
Tried out various things
I did of course search on the internet prior to coming to an expert forum.
I have tried the XSL:PRESERVE and XSL:OUTPUT approaches to no avail. Does anyone have a clue how to keep the formatting I have in my XML after the XSL transformation. I am thinking of re-writing this part of my application to produce Word documents via the MSWORD object model and junking the XML/XSL experiment. |
|
#6
|
||||
|
||||
|
Post (or attach) the XML and XSL files you have and I'll take a look.
|
|
#7
|
|||
|
|||
|
XML/XSL In question - sensitive info removed !
Thank you for offering to have a look at my hamfisted XML/XSL!
XML FILE - This is a cut down version of the actual file. the <ProcOverVw> element is where the formatting is lost. Code:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="XMLTest5.xsl"?>
<Procedures>
<ProcHead xml:space="preserve">
<ProcNbr>4</ProcNbr>
<ProcDept>SD</ProcDept>
<ProcTitle>Mailing History Upload</ProcTitle>
<ProcOuts> Mailing history records are appended to the mailinghistory_p table in the database.
Customer records have the SUPPRESSED field updated to ‘C’ where the cust_no exists in the control file.</ProcOuts>
<ProcAuth>A Developer</ProcAuth>
<ProcVrsn>1</ProcVrsn>
<ProcDate>10/06/04</ProcDate>
<ProcAmnd> </ProcAmnd>
<ProcOvrVw xml:space="preserve"><![CDATA[There are two parts to this process depending on the files received for upload.
1. Load mailing history data.
2. Update control records.
If a control file is received then the procedures to update these should be followed (steps 13 to 26) else these steps can be ignored.
File(s) are supplied by the Research Dept. The mailing history file is loaded into the mailinghist table in the database. The control file (if it is supplied) is loaded into the TEMP_CUST table using sqlload in UNIX then an update query is performed in SQL Plus.
Mailing History file :
The file being uploaded should be renamed to mailhist.txt and the format should match the control script (mailhist_p2.ctl) used for upload.
A log file is created during the upload (mailhist_p2.log). Any rejected records are written to a bad file (mailhist_p.bad).
Control file :
The file being uploaded should be renamed to control.txt and the format should match the control script (control.ctl) used for upload.
A log file is created during the upload (control.log). Any rejected records are written to a bad file (control.bad).
The log files contain the upload statistics, formatting applied to any columns and the reason that any records were rejected. The .bad files contain any records that have been rejected. If any bad files exists after uploads then check the contents. If it contains any records other than the header record then check the log file to determine why these records were rejected. These rejected records will need to be amended and re-uploaded. All records written to the database are committed. A maximum of fifty (50) records will be rejected befor the upload is aborted.]]></ProcOvrVw>
</ProcHead>
<ProcInstrs>
<ProcInstr>
</ProcInstr>
</ProcInstrs>
</Procedures>
Code:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"
indent="yes"
media-type="text/html"
cdata-section-elements="ProcOverVw"/>
<xsl:preserve-space elements="ProcOverVw" />
<!-- tell xslt which node to start with this is the top level template definition
the backslash says the context node is the root node i.e. the whole document -->
<xsl:template match="/">
<html>
<head>
<TITLE>Procedure Document(s)</TITLE>
</head>
<body style="font-family: Arial">
<!-- tell xslt you have templates you wish to use to process the CHILDREN of the start node -->
<xsl:apply-templates />
<br/>
</body>
</html>
</xsl:template>
<xsl:template match="ProcHead">
<xsl:variable name="overtxt" select = "ProcOverVw" />
<xsl:message>
$overtxt
</xsl:message>
<p><left><b><h2><xsl:value-of select="ProcTitle"/></h2></b></left></p>
<table align = "center" bgcolor="#9acd33" width="600">
<tr>
<td><b><xsl:text>Proc ID : </xsl:text></b></td>
<td><xsl:value-of select="ProcNbr"/></td>
</tr>
<tr>
<td><b><xsl:text>Department: </xsl:text></b></td>
<td><xsl:value-of select="ProcDept"/></td>
</tr>
<tr>
<td><b><xsl:text>Proc Author : </xsl:text></b></td>
<td><xsl:value-of select="ProcAuth"/></td>
</tr>
<tr>
<td><b><xsl:text>Date Written: </xsl:text></b></td>
<td><xsl:value-of select="ProcDate"/></td>
</tr>
<tr>
<td><b><xsl:text>Date Last Amended : </xsl:text></b></td>
<td><xsl:value-of select="ProcAmnd"/></td>
</tr>
<tr>
<td><b><xsl:text>Version Nbr: </xsl:text></b></td>
<td><xsl:value-of select="ProcVrsn"/></td>
</tr>
</table>
<p><b><xsl:text>Overview: </xsl:text></b></p>
<p>><xsl:value-of select="ProcOvrVw"/></p>
<p><b><xsl:text>Instructions: </xsl:text></b></p>
</xsl:template>
<xsl:template match="ProcInstrs">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="ProcInstr">
<p><xsl:value-of select="." /></p>
</xsl:template>
<xsl:template match="ProcBmp">
<img>
<xsl:attribute name="src">
<xsl:value-of select="@src" /><xsl:text> </xsl:text>
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="@alt" />
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="@width" />
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="@height" />
</xsl:attribute>
</img>
</xsl:template>
</xsl:stylesheet>
Last edited by jharnois : June 28th, 2004 at 05:42 PM. |
|
#8
|
||||
|
||||
|
Code:
<!-- <p>><xsl:value-of select="ProcOvrVw"/></p>--> <pre><xsl:value-of select="ProcOvrVw" /></pre> |
|
#9
|
|||
|
|||
|
Test solution
Thank you for the effort - I will try this today at some point and post how I got on !
Thanks again. |
|
#10
|
|||
|
|||
|
Eureka
The <pre> tag and CSS solution works a treat.
Many thanks............... |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Newbie to XML/XSLT/Whitespace problems |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|