[thelist] Basic XSLT problem

Blowhorn Kili2x at netscape.net
Mon Jan 12 11:02:56 CST 2004


"Nick Lester" <nick at flowbike.com> wrote:

>Hi all,
>
>I have a basic (I hope) XSLT problem.
>I have some XML that looks like this:
>
>Here is the source XML:
>
><data>
>      <record title="Mr" Forename="Nick" Surname="Lester" />
>      <record title="Mr" Forename="Joe" Surname="Bloggs" />
></data>
>
>The record node may have many different attributes so I dont want to
>define these in the stylesheet. There may also be an undetermined number
>of record nodes
>I need some kind of translation to make it look like this:
>
><data>
>      <record title="Mr">
>          <Forename>Nick</Forename>
>          <Surname>Lester</Surname>
>      </record>
>
>      <record title="Mr">
>          <Forename>Joe</Forename>
>          <Surname>Bloggs</Surname>
>      </record>
></data>
>
>Any help would be very much appreciated!

Assuming all 'record' elements are children of 'data' elements:

<?xml version='1.0' ?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
    <xsl:output indent='yes' />

    <xsl:apply-templates match='record'>
        <xsl:element name='record'>
            <xsl:attribute name='title'>
                <xsl:value-of select='@title' />
            </xsl:attribute>
            <xsl:element name='Forename'>
                <xsl:value-of select='@Forename' />
            </xsl:element>
            <xsl:element name='Surname'>
                <xsl:value-of select='@Surname' />
            </xsl:element>
        </xsl:element>
    </xsl:apply-templates>

    <!-- etc. -->

</xsl:stylesheet>

                              HTH.
                              The Cromnate


__________________________________________________________________
New! Unlimited Netscape Internet Service.
Only $9.95 a month -- Sign up today at http://isp.netscape.com/register
Act now to get a personalized email address!

Netscape. Just the Net You Need.


More information about the thelist mailing list