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

RE: Preserving indentation of first tag when copying X

Subject: RE: Preserving indentation of first tag when copying XML into HTML?
From: "Costello, Roger L." <costello@xxxxxxxxx>
Date: Thu, 21 Sep 2006 12:30:10 -0400
phone call template
Ah, yes, that's it.  Thanks Wendell.

    <xsl:template match="Member">
        <pre>
            <xsl:value-of disable-output-escaping="yes"
select="text()[last()]"/>
            <xsl:call-template name="xml-to-string">
                <xsl:with-param name="node-set" select="."/>
            </xsl:call-template>
        </pre>
    <xsl:template>

/Roger

-----Original Message-----
From: Wendell Piez [mailto:wapiez@xxxxxxxxxxxxxxxx]
Sent: Thursday, September 21, 2006 12:14 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Preserving indentation of first tag when copying XML
into HTML?

Roger,

It appears to me that the solution here lies in diagnosing exactly
why the indentation isn't happening where you want it.

This is undoubtedly related to why it is appearing where you do want
it.

There are generally two possibilities: either Evan's code is copying
it from your input, or it is providing its own indenting. You need to
look and see which it is.

Then you need to establish whether it is doing this correctly for the
first node or not: check the HTML result to see this. It's possible
that it is, but that your browser's handling of the pre element is
suppressing it.

That will probably lead you to a reasonable solution.

Assuming your browser is behaving the way you want it to with the
text node contents (the semantics of pre being what they are), you
could try, instead of copying "parent::*[1]/child::*[1]/text()", just
copy "text()[last()]" on the assumption that you want the first tag
(the start tag of your code bit) to be indented the same distance as
the last tag (the end tag).

Cheers,
Wendell

At 11:49 AM 9/21/2006, you wrote:
>Hi Folks,
>
>I am using Evan Lenz' stylesheet to copy XML into HTML.  I am
embedding
>the XML within an HTML <pre> element so that it retains all of its
>formatting.
>
>Everything works fine, except I am having a problem getting the start
>tag of the first XML element to be indented properly (lined up with
its
>end tag).
>
>Consider this XML of a Fitness Center:
>
><?xml version="1.0"?>
><FitnessCenter>
>         <Member level="platinum">
>                 <Name>Jeff</Name>
>                 <Phone type="home">555-1234</Phone>
>                 <Phone type="work">555-4321</Phone>
>                 <FavoriteColor>lightgrey</FavoriteColor>
>         </Member>
>         <Member level="gold">
>                 <Name>David</Name>
>                 <Phone type="home">383-1234</Phone>
>                 <Phone type="work">383-4321</Phone>
>                 <FavoriteColor>lightblue</FavoriteColor>
>         </Member>
>         <Member level="platinum">
>                 <Name>Roger</Name>
>                 <Phone type="home">888-1234</Phone>
>                 <Phone type="work">888-4321</Phone>
>                 <FavoriteColor>lightyellow</FavoriteColor>
>         </Member>
></FitnessCenter>
>
>Let's suppose that I want to copy Member[1] and embed it within HTML.
>Here's a template to do that:
>
>     <xsl:template match="Member">
>            <pre>
>                <xsl:call-template name="xml-to-string">
>                    <xsl:with-param name="node-set" select="."/>
>                </xsl:call-template>
>            </pre>
>     </xsl:template>
>
>(xml-to-string is Evan Lenz' named template.)
>
>Here is how it appears in a browser:
>
><Member level="platinum">
>                 <Name>Jeff</Name>
>                 <Phone type="home">555-1234</Phone>
>                 <Phone type="work">555-4321</Phone>
>                 <FavoriteColor>lightgrey</FavoriteColor>
>         </Member>
>
>Notice that the indentation for the Member start tag has disappeared.
>
>I want each element's start tag and end tag to line up.  I want it to
>look like this in the browser:
>
>         <Member level="platinum">
>                 <Name>Jeff</Name>
>                 <Phone type="home">555-1234</Phone>
>                 <Phone type="work">555-4321</Phone>
>                 <FavoriteColor>lightgrey</FavoriteColor>
>         </Member>
>
>Okay, so I thought, "let me obtain the whitespace between the parent
>tag and the Member start tag".  Here's what I tried:
>
>     <xsl:template match="Member">
>            <pre>
>                <xsl:value-of disable-output-escaping="yes"
>select="parent::*[1]/child::*[1]/text()"/>
>                <xsl:call-template name="xml-to-string">
>                    <xsl:with-param name="node-set" select="."/>
>                </xsl:call-template>
>            </pre>
>     </xsl:template>
>
>Here is how it appears in a browser:
>
>                 <Member level="platinum">
>                 <Name>Jeff</Name>
>                 <Phone type="home">555-1234</Phone>
>                 <Phone type="work">555-4321</Phone>
>                 <FavoriteColor>lightgrey</FavoriteColor>
>         </Member>
>
>Notice that now the Member start tag is indented too much.
>
>Can someone tell me how to do this so that the indentation of the
first
>tag is the same as it is in the instance document?
>
>Thanks.  /Roger

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.