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

Re: Processing formatted XML?

Subject: Re: Processing formatted XML?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 2 May 2002 10:04:30 +0100
formatted xml
Hi Robert,

> Can anybody give me any points as to how to process formatted, for
> the sake of readability, and generate readable ascii Text?
>
> Specifically I want to know what the stylesheet should do maintain
> format but at the same time remove leading and trailing spaces.

>From your description, I think that you want to preserve the line
break characters ('&#xA;') and get rid of the space characters (' ')
in the value of the note elements. You can do this with the
translate() function -- translating all the spaces into nothing:

<xsl:template match="note">
  <note>
    <xsl:value-of select="translate(., ' ', '')" />
  </note>
</xsl:template>

If you have tabs in the whitespace, you should include them in the
translate as well:

  <xsl:value-of select="translate(., ' &#x9;', '')" />

If you then want to strip the leading and trailing line breaks -- at
the start and end of the string value of the note element, you can use
the substring() function:

  <xsl:variable name="note" select="translate(., ' &#x9;', '')" />
  <xsl:value-of select="substring($note, 2, string-length($note) - 2)"/>

(Note that this assumes that all your notes have a leading and
trailing newline character -- you might want to check for that first.)
  
> I have two rules
>
> <xsl:template match="notes">
> <xsl:call-template name="separated-list">
>         <xsl:with-param name="nodes" select="note"/>
>         <xsl:with-param name="separator">
>         </xsl:with-param>
> </xsl:call-template>
> </xsl:template>

Currently, you're not setting the $separator parameter to anything
(well, only to an empty string) with this code. Whitespace in the
stylesheet is stripped out when the stylesheet is read, unless it's
held within an xsl:text element or you use xml:space="preserve", so
the above call is exactly the same as:

  <xsl:call-template name="separated-list">
    <xsl:with-param name="nodes" select="note" />
    <xsl:with-param name="separator"></xsl:with-param>
  </xsl:call-template>

If you want to set the separator to a newline character followed by
some spaces, then you should use xsl:text to hold that whitespace --
that way it won't be stripped.

  <xsl:call-template name="separated-list">
    <xsl:with-param name="nodes" select="note" />
    <xsl:with-param name="separator">
      <xsl:text>&#xA;    </xsl:text>
    </xsl:with-param>
  </xsl:call-template>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.