Re: [xsl] Newline problems

Subject: Re: [xsl] Newline problems
From: "Vishwajit Pantvaidya" <pantvaidya@xxxxxxxxxxx>
Date: Mon, 05 May 2003 16:40:57 -0700

From: Mike Brown <mike@xxxxxxxx>
Date: Fri, 2 May 2003 22:54:31 -0600 (MDT)

Vishwajit Pantvaidya wrote:
> I made changes to apply normalize-space to text nodes as suggested but
> output again has no data. Do you see any obvious mistakes? Simplified src
> xml and xsl are as shown below:
> ----------------------------------------------XML------------------
> ...
> ]><ABC>
> ...
> <info>
> <attr>
> <name>
> ponumber</name>
> <atomicValue>
> 12345</atomicValue>
> </attr>
> ...
> </info>
> ...
> </ABC>
> ----------------------------------------------XSL------------------
> <?xml version = "1.0" encoding = "UTF-8"?>
> <xsl:transform xmlns:xsl = ""; version =
> "1.0">
> <xsl:template match = "ABC">
> <xsl:text disable-output-escaping="yes">&lt;!DOCTYPE
> OrderProcessing&gt;</xsl:text>
> <xsl:element name = "Order">
> <xsl:element name ="Info">
> <xsl:apply-templates mode = "Attribs" select = "/ABC/info"/>

I think here you just want to select "info", not "/ABC/info", because you are
currently processing an ABC element and you just want *its* info child, not
the set of all info children, no?

>       </xsl:element>
>     </xsl:element>
>   </xsl:template>
>   ...
>   <xsl:template mode = "Attribs" match = "info">
>     <xsl:apply-templates mode = "stripNewline" select="text()"/>

Look at your XML. The only text node *children* of the info element
are whitespace. There are some other child nodes that are elements
and *those* have text node children. But you are not selecting any
of those.

Does this mean that I have to reply the xsl:value-of for ponumber with apply-templates and then do the normalize-space in that template processing. But apart from ponumber, I am reading other data similarly, (which also has newlines) and does this mean that I have to have a template for each of such data attributes? Is there an optimal way of not only removing newlines from all such data items but also copying them into the output xml?

Specifically what text from the source are you trying to insert before the PO_NUMBER element you create?

>     <xsl:element name = "PO_NUMBER">
>       <xsl:value-of select="attr/atomicValue[../name='ponumber']"/>
>     </xsl:element>
>   ...

Is there any reason why you use xsl:element instead of just

Actually, I inherited this xsl sheet from another person and am left with the task of maintaining it. Hence the innumerable questions :)

> </xsl:template> > > <xsl:template mode = "stripNewline" match="text()"> > <xsl:value-of select="normalize-space(.)"/> > </xsl:template> > ... > </xsl:transform>

I meant to mention, normalize-space might be overkill; if you want
to remove *just* LF chars, use translate(.,'
',''). However this
will result in other whitespace (such as spaces or tabs used for
indenting) being left intact.

To use the above, do I have to type an actual newline into the xsl sheet or can I specify it in any other way?




The new MSN 8: smart spam protection and 2 months FREE*

XSL-List info and archive:

Current Thread