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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preserve White Space?

Status
Not open for further replies.

Smeat

Programmer
Mar 27, 2004
193
GB
Hi

I'm using an xslt to transform an xml doc and this works correctly.

My issue if that the xml in the target file is all on a single line making it difficult to view in an editor.

Id there a way I can instruct to XSLT to preserve the line breaks so that it is easier to read once transformed?

Thanks in advance for any help

Smeat
 
The following is the xslt file:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
<xsl:template match="/">
<Vehicles>
<xsl:apply-templates />
</Vehicles>
</xsl:template>

<xsl:template match="Vehicle">
<Vehicle>
<Make><xsl:value-of select="Make" /></Make>
<Model><xsl:value-of select="Model" /></Model>
<Derivative><xsl:value-of select="Range" /></Derivative>
<FuelType><xsl:value-of select="Fuel" /></FuelType>
<GearBoxType><xsl:value-of select="Transmission" /></GearBoxType>
<InsuranceGroup><xsl:value-of select="InsuranceGroup" /></InsuranceGroup>
<SellingPrice><xsl:value-of select="RetailPrice" /></SellingPrice>
<Mileage><xsl:value-of select="Mileage" /></Mileage>
<CC><xsl:value-of select="EngineCC" /></CC>
<Registration><xsl:value-of select="Registration" /></Registration>
<Options>
<xsl:apply-templates select="Options" />
</Options>

<Images>
<xsl:apply-templates select="Images" />
</Images>
</Vehicle>
</xsl:template>


<xsl:template match="Options">
<xsl:for-each select="Option">
<Option>
<OptionCode><xsl:value-of select="Code" /></OptionCode>
<OptionDescription><xsl:value-of select="Description" /></OptionDescription>
</Option>
</xsl:for-each>
</xsl:template>

<xsl:template match="Images">
<xsl:for-each select="Image">
<Image>
<ImageData><xsl:value-of select="Fullsize" /></ImageData>
</Image>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
 
You might look at using the xml:space attribute.

But really, XML doesn't care about whitespace between elements -- an XML parser treats it all the same. It's only when we humans want to look at a document that people start complaining. I would invest in a good XML-aware editor, or for casual users, just have them use Internet Explorer.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top