xsl-list
[Top] [All Lists]

Re: write text using XSLT

2005-08-22 15:16:37
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:stylesheet 
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
    
    <xsl:output method="text" />
    
    <xsl:template match="/">
        <xsl:text>product_number,product,quantity,size</xsl:text>
        <xsl:call-template name="br" />
        <xsl:apply-templates />
    </xsl:template>
    
    <xsl:template match="...">
        <xsl:value-of
select="description/@product_number"/>,<xsl:value-of
select="description"/>,<xsl:value-of select="quantity"/>,<xsl:value-of
select="size"/>
        <xsl:call-template name="br" />
    </xsl:template>
    
    <!-- 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>
</xsl:stylesheet>

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,


Will.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>