Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Re: XSLT converting attributes to elements and renaming at the same time...

Reply
Thread Tools

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

 
 
Colin Mackenzie
Guest
Posts: n/a
 
      07-10-2003

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" <(E-Mail Removed)> wrote in message
news:bejl94$2nf$1$(E-Mail Removed)...
> 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"
> xmlnssl="http://www.w3.org/1999/XSL/Transform">
> <xslutput 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....
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT: how to get either specific attributes or all elements under a parent element hisachu XML 0 09-01-2010 05:40 PM
XSLT to Remove Elements with Specific Attributes? Aaron Davies XML 4 02-11-2009 04:13 PM
XSLT: iterating all child elements and accessing homonymous childrenin sibling elements Gerald Aichholzer XML 2 06-27-2006 03:46 PM
XSLT: remove multiple elements having same child element content Johannes Koch XML 1 03-05-2004 02:30 PM
XSD question (same attributes, different elements...) Gooseman XML 1 01-22-2004 11:27 AM



Advertisments