Basic XSLT question

Discussion in 'XML' started by Paul Smith, Aug 11, 2003.

  1. Paul  Smith

    Paul Smith Guest

    Apologies, I am new to XSLT. I am having trouble with something that I
    would expect to be quite straightforward.

    How do I leave XML tags as they are in a transformation? From the XML
    below, I want to apply a stylesheet such that the XML is exactly the
    same apart from the only <row> should be the first one from the XML
    below. I can output some text for position()=1 but I can't output the
    original XML too. So the only thing I get in my whole output document
    is "Found it"!

    Any help would be greatly appreciated.


    Original XML:
    <?xml version="1.0" encoding="UTF-8"?>
    <xmlresults status="SDSUCCESS">
    <tablemetadata>
    <tablemetadataitem name="TABLE1" description="Table 1"/>
    </tablemetadata>
    <columnmetadata>
    <columnmetadataitem name="COL1" description="Col 1" pos="2"/>
    <columnmetadataitem name="COL2" description="Col 2" pos="1"/>
    </columnmetadata>
    <othertag>
    <othertagitem name="Type" value="Something"/>
    <othertagitem name="Direction" value="ASC"/>
    </parameterdata>
    <data>
    <row>
    <dataitem name="COL1" value="ABC"/>
    <dataitem name="COL2" value="123"/>
    </row>
    <row>
    <dataitem name="COL1" value="DEF"/>
    <dataitem name="COL2" value="456"/>
    </row>
    </data>
    </xmlresults>

    Required Output from XSL transformation (note the second <row> is
    missing):
    <?xml version="1.0" encoding="UTF-8"?>
    <xmlresults status="SDSUCCESS">
    <tablemetadata>
    <tablemetadataitem name="TABLE1" description="Table 1"/>
    </tablemetadata>
    <columnmetadata>
    <columnmetadataitem name="COL1" description="Col 1" pos="2"/>
    <columnmetadataitem name="COL2" description="Col 2" pos="1"/>
    </columnmetadata>
    <othertag>
    <othertagitem name="Type" value="Something"/>
    <othertagitem name="Direction" value="ASC"/>
    </parameterdata>
    <data>
    <row>
    <dataitem name="COL1" value="ABC"/>
    <dataitem name="COL2" value="123"/>
    </row>
    </data>
    </xmlresults>

    My XSL (for what it's worth):
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:eek:utput method="html" indent="yes"/>

    <xsl:template match="data">
    <xsl:for-each select="row">
    <xsl:choose>
    <xsl:when test="position() = 1">
    Found It
    </xsl:when>
    </xsl:choose>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>
     
    Paul Smith, Aug 11, 2003
    #1
    1. Advertising

  2. In article <>,
    Paul Smith <> wrote:

    >How do I leave XML tags as they are in a transformation? From the XML
    >below, I want to apply a stylesheet such that the XML is exactly the
    >same apart from the only <row> should be the first one from the XML
    >below.


    You need a template that copies everything else. This will copy everything
    that doesn't have a more specific template:

    <xsl:template match="@*|node()">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:template>

    Your template for data will work, but it would be simpler to just have a
    template for the non-first rows that does nothing:

    <xsl:template match="row[position() > 1]">
    </xsl:template>

    -- Richard
    --
    Spam filter: to mail me from a .com/.net site, put my surname in the headers.

    FreeBSD rules!
     
    Richard Tobin, Aug 11, 2003
    #2
    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. LW
    Replies:
    1
    Views:
    406
    Dimitre Novatchev
    Sep 18, 2003
  2. Justine Hlista

    Basic XSLT/XSLTC question

    Justine Hlista, Mar 3, 2004, in forum: XML
    Replies:
    3
    Views:
    572
    Dimitre Novatchev [MVP XML]
    Mar 4, 2004
  3. Engineer
    Replies:
    6
    Views:
    643
    Jeremy Bowers
    May 1, 2005
  4. Replies:
    0
    Views:
    452
  5. Replies:
    18
    Views:
    2,779
    Joseph Kesselman
    Oct 4, 2006
Loading...

Share This Page