xsl duplicates data

Discussion in 'XML' started by 1984to911@gmail.com, Sep 9, 2008.

  1. Guest

    I have an XML of the form

    <grandparent>
    <top_element>
    data
    <special_element>special data</special_element>
    </top_element>

    <second_element>
    <some_element>some data</some_element>
    <special_element>other special data </special_element>
    <some_other_element>some other data</some_other_element>
    <second_element>
    </grandparent>

    I'm trying to get html output of the form

    <div>
    some data
    <div>other special data </div>
    some other data
    </div>


    so far the best I can get is
    <div>
    some data
    other special data
    some other data
    <div>other special data</div>
    </div>

    by using
    <xsl:template match="second_element">
    <div><xsl:value-of select="."/>

    <xsl:apply-templates select=".//special_element"/>
    </div>
    </xsl:template>

    <xsl:template match="//second_element//special_element">
    <div >
    <xsl:value-of select="."/></div>
    </xsl:template>
     
    , Sep 9, 2008
    #1
    1. Advertising

  2. Pavel Lepin Guest

    <> wrote in
    <>:
    > <grandparent>
    > <top_element>
    > data
    > <special_element>special data</special_element>
    > </top_element>
    >
    > <second_element>
    > <some_element>some data</some_element>
    > <special_element>other special data </special_element>
    > <some_other_element>some other data</some_other_element>
    > <second_element>


    Not well-formed.

    > </grandparent>
    >
    > I'm trying to get html output of the form
    >
    > <div>
    > some data
    > <div>other special data </div>
    > some other data
    > </div>


    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <xsl:apply-templates
    select="grandparent/second_element"/>
    </xsl:template>
    <xsl:template match="second_element|special_element">
    <xsl:element name="div">
    <xsl:apply-templates/>
    </xsl:element>
    </xsl:template>
    </xsl:stylesheet>

    --
    Waterfall - One Process To Rule Them All
     
    Pavel Lepin, Sep 10, 2008
    #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. Kevin Flood
    Replies:
    0
    Views:
    1,040
    Kevin Flood
    Sep 8, 2004
  2. Replies:
    1
    Views:
    3,656
    A. Bolmarcich
    May 27, 2005
  3. Replies:
    0
    Views:
    543
  4. Mike Copeland
    Replies:
    3
    Views:
    424
    Jerry Coffin
    May 14, 2008
  5. basi
    Replies:
    4
    Views:
    179
    Wayne Vucenic
    Aug 1, 2005
Loading...

Share This Page