[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: write text using XSLT

Subject: Re: write text using XSLT
From: Will McCutchen <mccutchen@xxxxxxxxx>
Date: Mon, 22 Aug 2005 17:16:37 -0500
linebreak xslt
> 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.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.