Re: [xsl] write text using XSLT

Subject: Re: [xsl] write text using XSLT
From: Will McCutchen <mccutchen@xxxxxxxxx>
Date: Mon, 22 Aug 2005 17:16:37 -0500
> In the above stylesheet I want
> product_number,product_id,quantity,size to be written
> into the text format only once. But for each product
> row I get the above names written. Kindly suggest me
> how to solve the above problem.

It would be easier to answer your question if you included at least
part of your XML source document.  Without that, here is my (untested,
quick) suggestion, which might serve as a sort of outline (it's also
attached, to preserve formatting):


    <xsl:output method="text" />

    <xsl:template match="/">
        <xsl:call-template name="br" />
        <xsl:apply-templates />

    <xsl:template match="...">
select="description"/>,<xsl:value-of select="quantity"/>,<xsl:value-of
        <xsl:call-template name="br" />

    <!-- this template just inserts a line break, so it's called
         after each line -->
    <xsl:template name="br"><xsl:text>&#13;</xsl:text></xsl:template>

I don't know what element the second template should match, since you
didn't provide some example XML source, so you'll need to fill that in
on your own.

I added a template named br, which is something I have found useful
when using XSL to output plain text.  In my real "br" template,
there's an <xsl:choose> block which outputs platform-specific line
breaks based on an $output-platform parameter.

Hope this helps,


Current Thread