help! new to xslt

Discussion in 'XML' started by timothy ma and constance lee, Oct 7, 2004.

  1. Sirs/Madam

    I am new to xslt but got a trouble

    I get the xml messgae like

    <message>
    <docList>
    <docSet>1</docSet>
    <docTp>A1/docTp>
    <docSet>1</docSet>
    <docTp>B1</docTp>
    <docSet>2</docSet>
    <docTp>A2</docTp>
    <docSet>1</docSet>
    <docTp>C1</docTp>
    <docSet>2</docSet>
    <docTp>B2</docTp>

    I need to have xslt to make html like

    DocSet 1
    Doc Tp = A1
    Doct Tp = B1
    Doc Tp = C1

    DocSet2
    DocTp = A2
    ......

    Please suggest
    </docList>
    timothy ma and constance lee, Oct 7, 2004
    #1
    1. Advertising

  2. timothy ma and constance lee

    Mukul Gandhi Guest

    This is a grouping problem, and can be solved using the Muenchian
    technique -

    <?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:key name="by-docSet" match="docSet" use="." />

    <xsl:template match="/message">
    <html>
    <head>
    <title/>
    </head>
    <body>
    <table>
    <xsl:for-each select="docList/docSet[generate-id(.) =
    generate-id(key('by-docSet', .)[1])]">
    <tr>
    <td>
    DocSet
    </td>
    <td>
    <xsl:value-of select="." />
    </td>
    </tr>
    <xsl:for-each select="key('by-docSet', .)">
    <tr>
    <td>
    Doc Tp =
    </td>
    <td>
    <xsl:value-of select="following-sibling::docTp[1]" />
    </td>
    </tr>
    </xsl:for-each>
    </xsl:for-each>
    </table>
    </body>
    </html>
    </xsl:template>

    </xsl:stylesheet>

    Regards,
    Mukul

    "timothy ma and constance lee" <> wrote in message news:<qb39d.11924$a41.9354@pd7tw2no>...
    > Sirs/Madam
    >
    > I am new to xslt but got a trouble
    >
    > I get the xml messgae like
    >
    > <message>
    > <docList>
    > <docSet>1</docSet>
    > <docTp>A1/docTp>
    > <docSet>1</docSet>
    > <docTp>B1</docTp>
    > <docSet>2</docSet>
    > <docTp>A2</docTp>
    > <docSet>1</docSet>
    > <docTp>C1</docTp>
    > <docSet>2</docSet>
    > <docTp>B2</docTp>
    >
    > I need to have xslt to make html like
    >
    > DocSet 1
    > Doc Tp = A1
    > Doct Tp = B1
    > Doc Tp = C1
    >
    > DocSet2
    > DocTp = A2
    > .....
    >
    > Please suggest
    > </docList>
    Mukul Gandhi, Oct 7, 2004
    #2
    1. Advertising

  3. timothy ma and constance lee

    William Park Guest

    timothy ma and constance lee <> wrote:
    > Sirs/Madam
    >
    > I am new to xslt but got a trouble
    >
    > I get the xml messgae like
    >
    > <message>
    > <docList>
    > <docSet>1</docSet>
    > <docTp>A1/docTp>
    > <docSet>1</docSet>
    > <docTp>B1</docTp>
    > <docSet>2</docSet>
    > <docTp>A2</docTp>
    > <docSet>1</docSet>
    > <docTp>C1</docTp>
    > <docSet>2</docSet>
    > <docTp>B2</docTp>
    >
    > I need to have xslt to make html like
    >
    > DocSet 1
    > Doc Tp = A1
    > Doct Tp = B1
    > Doc Tp = C1
    >
    > DocSet2
    > DocTp = A2
    > .....
    >
    > Please suggest
    > </docList>


    Off topic... but if you have Expat XML parser (www.libexpat.org) and my
    patched Bash shell (http://freshmeat.net/projects/bashdiff/),

    func () { # Usage: func data
    case ${XML_ELEMENT_STACK[1]} in
    docTp) echo "$docSet $1" ;;
    docSet) docSet=$1 ;;
    esac
    }
    xml -d func "<message> ... </message>"

    you will get

    1 A1
    1 B1
    2 A2
    1 C1
    2 B2

    I'll leave it as homework for you to convert to the format you want.

    --
    William Park <>
    Open Geometry Consulting, Toronto, Canada
    William Park, Oct 7, 2004
    #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:
    621
    Stylus Studio
    Aug 3, 2004
  2. Benjamin Hillsley
    Replies:
    3
    Views:
    1,648
    Dimitre Novatchev
    Sep 25, 2003
  3. ted
    Replies:
    1
    Views:
    607
    Laurens
    Jan 26, 2004
  4. Replies:
    2
    Views:
    701
    Henry S. Thompson
    Oct 19, 2005
  5. Replies:
    2
    Views:
    400
    Thomas 'PointedEars' Lahn
    Mar 11, 2008
Loading...

Share This Page