Re: XSLT converting attributes to elements and renaming at the same time...

Discussion in 'XML' started by Colin Mackenzie, Jul 10, 2003.

  1. so your input xml is like

    <Booking>
    <res ResNo="123" NumberofNights="1"/>

    in that case to access an attribute use @ ie <xsl:value-of select="ResNo"/>

    saying <xsl:value-of select="ResNo"/> mans look for the child element named
    ResNo

    Colin

    "Pete" <> wrote in message
    news:bejl94$2nf$1$...
    > Hi,
    > I have a simple enough xsl page as shown below but it doesnt quite

    work.
    > It prints empty elements instead of containing the data. The style sheet

    is
    > being parsed and output for each record returned by the original xml doc,
    > just nothing in the element.
    >
    > I am trying to convert from a flat list of attributes (returned by FOR XML
    > AUTO) into a list of elements with different names to their original

    column
    > identifiers. I cannot output from the sql as elements for reasons i wont

    go
    > into here and i cannot rename the attributes within the sql either.
    >
    > Each line in the code below that is value-of select=",,,," is the correct
    > colum name returned by the sql.
    >
    > <?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="xml" version="1.0" encoding="iso-8859-1"
    > indent="yes"/>
    > <xsl:template match = "/">
    > <Bookings>
    > <xsl:for-each select="/Booking/res">
    > <Res>
    > <ResNo>
    > <xsl:value-of select="ResNo" />
    > </ResNo>
    > <Nights>
    > <xsl:value-of select="NumberofNights" />
    > </Nights>
    > <MAdults>
    > <xsl:value-of select="NumberofMaleAdults" />
    > </MAdults>
    > <FAdults>
    > <xsl:value-of select="NumberofFemaleAdults" />
    > </FAdults>
    > <MChildren>
    > <xsl:value-of select="NumberofMaleChildren" />
    > </MChildren>
    > <FChildren>
    > <xsl:value-of select="NumberofFemaleChildren" />
    > </FChildren>
    > <From>
    > <xsl:value-of select="TravellingFrom" />
    > </From>
    > </Res>
    > </xsl:for-each>
    > </Bookings>
    > </xsl:template>
    > </xsl:stylesheet>
    >
    > This is what i get...
    >
    > <?xml version="1.0" ?>
    > - <Bookings>
    > - <Res>
    > <ResNo />
    > <Nights />
    > <MAdults />
    > <FAdults />
    > <MChildren />
    > <FChildren />
    > <From />
    > </Res>
    > - <Res>
    > <ResNo />
    > <Nights />
    > <MAdults />
    > <FAdults />
    > <MChildren />
    > <FChildren />
    > <From />
    > </Res>
    > - <Res>
    > <ResNo />
    > <Nights />
    > <MAdults />
    > <FAdults />
    > <MChildren />
    > <FChildren />
    > <From />
    > </Res>
    > - <Res>
    > <ResNo />
    > <Nights />
    > <MAdults />
    > <FAdults />
    > <MChildren />
    > eetc....
    >
    >
    Colin Mackenzie, Jul 10, 2003
    #1
    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. Gooseman
    Replies:
    1
    Views:
    409
    DFN-CIS NetNews Service
    Jan 22, 2004
  2. Martin Plantec
    Replies:
    6
    Views:
    1,165
    Martin Plantec
    Oct 31, 2005
  3. Gerald Aichholzer
    Replies:
    2
    Views:
    2,495
    Gerald Aichholzer
    Jun 27, 2006
  4. Aaron Davies
    Replies:
    4
    Views:
    4,230
    The Magpie
    Feb 11, 2009
  5. hisachu
    Replies:
    0
    Views:
    1,536
    hisachu
    Sep 1, 2010
Loading...

Share This Page