Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 7th, 2011, 07:43 AM
Registered User
 
Join Date: Jul 2011
Posts: 3
Thanks: 3
Thanked 0 Times in 0 Posts
Post Formatting Output

Hello, I am wondering/ having a problem figuring out formatting in XSLT.

I have this XSL
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" encoding="utf-8" indent="no" />
   
   <!-- MasterClip Vars -->
  <xsl:variable name="fields" select="'|clip_description|episode_no|rushes_roll_number|source_image_format|technical_comments|broadcast_time|first_broadcast_channel|Keywords|original_transmission_date|episode_title|contributor'" />
   
    <!--Global-->
    <xsl:template match="Global">
        <Global>
            <xsl:apply-templates />
        </Global>
    </xsl:template>

    <xsl:template match="GlobalParam">
        <GlobalParam>
            <xsl:attribute name="name">
                <xsl:value-of select="@name" />
            </xsl:attribute>
            <xsl:attribute name="value">
                <xsl:value-of select="@value" />
            </xsl:attribute>
        </GlobalParam>
    </xsl:template>
 
 <!---Roll--> 
 <xsl:template match="Roll">
  <xsl:copy/>
</xsl:template>

 
 
 
 <!--MasterClip -->
     
    <xsl:template match="@*|node()">
        <xsl:copy>
        <xsl:apply-templates select="@*|node()" />
        <xsl:text>
		</xsl:text>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="MasterClip">
        <xsl:copy>
            <xsl:apply-templates select="*[contains($fields, concat('|', @name, '|'))]" />
        </xsl:copy>
       
	
    </xsl:template>
    
</xsl:stylesheet>
And it gives me the correct output , but if you can see....


Code:
<FileImport>
  <Global>
    <GlobalParam name="RollName" value="Scene_Around_Six_Tape_3_BUFVC003-14 10:00:00:00" />
    <GlobalParam name="TapeOrg" value="10:00:00:00" />
    <GlobalParam name="ReadStart" value="00:00:00:00" />
    <GlobalParam name="ReadDuration" value="00:02:26:18" />
  </Global>
  <Roll />
  <MasterClip><Field name="clip_description" value="Interview Captain Austin Ardill re Terence O'Neill" group="Ingest">
		</Field><Field name="rushes_roll_number" value="" group="Ingest">
		</Field><Field name="source_image_format" value="" group="Ingest">
		</Field><Field name="technical_comments" value="" group="Ingest">
		</Field><Field name="broadcast_time" value="18:00" group="">
		</Field><Field name="first_broadcast_channel" value="" group="">
		</Field><Field name="original_transmission_date" value="27/01/1969 00:00:00" group="">
		</Field><Field name="episode_title" value="Scene_Around_Six_27_01_1969" group="News Archive">
		</Field></MasterClip>

		</FileImport>
In my output for MasterClip it starts directly with the next tag e.g <MasterClip><Field name= .... And ends " </Field></MasterClip>" On the same line , the root element end tag also gets indented , what i would like is that the MasterClip tags start and end on their own line and that the </FileImport> tag has no indentation.

I have tried a few different ways but with no success . If possible could you help me and provide an explanation , maybe common tips/tricks to keep me right. Thank you for your time.
 
Old July 7th, 2011, 07:51 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Consider to post the XML input document.
Generally if you want to indent your result XML and don't want to copy any white space from the input then do
Code:
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog

Last edited by Martin Honnen; July 7th, 2011 at 07:53 AM..
The Following User Says Thank You to Martin Honnen For This Useful Post:
amendir (July 7th, 2011)
 
Old July 7th, 2011, 08:02 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You haven't shown the source document. My guess is the unwanted whitespace is being copied from the source. The indent="no" option isn't allowed to mess about with whitespace between a "simple content" start and end tag.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
amendir (July 7th, 2011)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting Time Output braunj ASP.NET 2.0 Basics 0 October 6th, 2008 10:27 PM
Formatting Database Output Gobbles Classic ASP Basics 3 September 25th, 2007 05:08 AM
Output Formatting Neal XSLT 2 October 12th, 2006 05:12 AM
ASP to Excel - excel output formatting issue mat41 Classic ASP Professional 0 August 13th, 2006 06:41 AM
Formatting Output Colonel Angus SQL Server 2000 3 September 1st, 2004 10:35 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.