[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Newline problems


Subject: Re: [xsl] Newline problems
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------------------
> <!DOCTYPE ABC [
> ...
> ]><ABC>
> ...
> <info>
> <attr>
> <name>
> ponumber</name>
> <atomicValue>
> 12345</atomicValue>
> </attr>
> ...
> </info>
> ...
> </ABC>
> 
> ----------------------------------------------XSL------------------
> 
> <?xml version = "1.0" encoding = "UTF-8"?>
> <xsl:transform xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" 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.

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
<PO_NUMBER>...</PO_NUMBER>?

>   </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(.,'&#10;',''). However this
will result in other whitespace (such as spaces or tabs used for
indenting) being left intact.

Mike

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



Current Thread
Keywords