How to do this in XSLT

Discussion in 'XML' started by Sandy, Dec 12, 2005.

  1. Sandy

    Sandy Guest

    Hi,

    I have following XML. I want to write an XSL file which can take the first
    and second <NAME> elements and put them in the output (which is a csv file
    as shown below).
    But i am not able to find how to do this using XSLT transformations.

    Any help is greatly appreciated.

    Input XML file
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xml" href="test.xsl"?>
    <LIST>
    <NAME>
    <FIRST>first1</FIRST>
    <LAST>last1</LAST>
    </NAME>
    <NAME>
    <FIRST>first2</FIRST>
    <LAST>last2</LAST>
    </NAME>
    <NAME>
    <FIRST>first3</FIRST>
    <LAST>last3</LAST>
    </NAME>
    <NAME>
    <FIRST>first4</FIRST>
    <LAST>last4</LAST>
    </NAME>
    ................
    ..................... (n number of NAME's)
    </LIST>

    *****************************************************************
    Output

    first1,Last1
    first2,last2
    Sandy, Dec 12, 2005
    #1
    1. Advertising

  2. Sandy

    JAPISoft Guest

    Hi Sandy,

    Here a sample, please use an editor for checking the syntax, it is
    written without one :

    ....

    <xsl:eek:utput method="text"/>

    <xsl:template match="LIST">
    <xsl:apply-templates select="NAME"/>
    </xsl:template>

    <xsl:template match="NAME">
    <xsl:value-of select="FIRST"/>,<xsl:value-of select="LAST"/>
    </xsl:template>

    Best regards,

    A.Brillant
    Editix - XML Editor and XSLT Debugger
    http://www.editix.com

    Sandy wrote:
    > Hi,
    >
    > I have following XML. I want to write an XSL file which can take the first
    > and second <NAME> elements and put them in the output (which is a csv file
    > as shown below).
    > But i am not able to find how to do this using XSLT transformations.
    >
    > Any help is greatly appreciated.
    >
    > Input XML file
    > <?xml version="1.0"?>
    > <?xml-stylesheet type="text/xml" href="test.xsl"?>
    > <LIST>
    > <NAME>
    > <FIRST>first1</FIRST>
    > <LAST>last1</LAST>
    > </NAME>
    > <NAME>
    > <FIRST>first2</FIRST>
    > <LAST>last2</LAST>
    > </NAME>
    > <NAME>
    > <FIRST>first3</FIRST>
    > <LAST>last3</LAST>
    > </NAME>
    > <NAME>
    > <FIRST>first4</FIRST>
    > <LAST>last4</LAST>
    > </NAME>
    > ...............
    > .................... (n number of NAME's)
    > </LIST>
    >
    > *****************************************************************
    > Output
    >
    > first1,Last1
    > first2,last2
    >
    >
    JAPISoft, Dec 12, 2005
    #2
    1. Advertising

  3. Sandy

    Matt Sannes Guest

    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="text" />
    <xsl:template match="*">
    <apply-templates/>
    </xsl:template>

    <xsl:template match="LIST">
    <xsl:for-each select="NAME">
    <xsl:value-of select="FIRST"/>,<xsl:value-of
    select="LAST"/><xsl:text>
    </xsl:text>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

    Matthew Sannes
    Docsoft .NET Developer

    Try our new Enterprise Search Engine geared towards XML repositories.
    Go to www.whatthexml.com for info.
    Matt Sannes, Dec 12, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stylus Studio
    Replies:
    0
    Views:
    655
    Stylus Studio
    Aug 3, 2004
  2. Benjamin Hillsley
    Replies:
    3
    Views:
    1,677
    Dimitre Novatchev
    Sep 25, 2003
  3. ted
    Replies:
    1
    Views:
    621
    Laurens
    Jan 26, 2004
  4. Replies:
    2
    Views:
    718
    Henry S. Thompson
    Oct 19, 2005
  5. Replies:
    4
    Views:
    668
Loading...

Share This Page