[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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(., ' 	', '')" /> 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(., ' 	', '')" /> <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>
 </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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|