This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Processing 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 ('
') 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]