![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: triple xsl:for-each problem? Please any suggestion >Thread Next - Re: triple xsl:for-each problem? Please any suggestion Re: triple xsl:for-each problem? Please any suggestionTo: NULL Date: 7/13/2006 12:21:00 PM "ina" <roberta.inalbon@g...> wrote in message news:1152773675.498037.59280@3...... > Thank you Antony for your time and answer. Really appreciate. > But I am sorry to be newbie in XML and ask, as you pretend, "stupid > question" because I am learning XML/XSLT. > > Really, I do not understand why in this group people are so arogant! > Well let me explain it to you. Most people in this group who have the answers do so in their spare time which often is limited. We want to help but many of us don't have the time to both answer the technical question and also sugar coat the facts just in case others might take offence. So there is a tendancy to just state the facts. It's an unfortunate nature of text based comminication that this can seem cold. There is no intent to make a person feel bad, just a desire to provide the raw help without the social frills. Basically NGs in general are not places to be if you have a thin skin and you need to recognise that the tone in which you read message is not necessarily the one it was written in. > Ina > > > Anthony Jones wrote: > > "ina" <roberta.inalbon@g...> wrote in message > > news:1152277641.303201.170200@m...... > > > Hello, > > > > > > I have a xml file with this structure > > > > > > <root> > > > <rooms> > > > <roomsA price="56"/> > > > <date>26/02/2006</date> > > > <roomsA> > > > <roomA price="65"/> > > > <date>26/03/2006</date> > > > </roomsA> > > > > > > <roomB price="59"> > > > <date>26/02/2006</date> > > > </roomB> > > > <roomB price="75"> > > > <date>26/03/2006</date> > > > </roomB> > > > <roomC price="45"> > > > <date>26/02/2006</date> > > > </roomC> > > > <roomC price="75"> > > > <date>26/03/2006</date> > > > </roomC> > > > </rooms> > > > </root> > > > > > > > > > and I would like to obtain something like this > > > > > > <Room> > > > <date>26/02/2006</date> > > > <roomsAprice>56</roomsAprice> > > > <roomsBprice>59</roomsBprice> > > > <roomsCprice>45</roomsCprice> > > > </Room> > > > <Room> > > > <roomsAprice>65</roomsAprice> > > > <roomsBprice>75</roomsBprice> > > > <roomsCprice>75</roomsCprice> > > > <Date>26/03/2006</Date> > > > </Room> > > > > > > > > > > I'm afraid the XML you are starting off with is poor quality but your > > proposed output is even worse. > > > > The fact your initial example is inconsistent it's makes it difficult to > > see what help you really need. > > > > Might I suggest the clean output XML that is required is:- > > > > <root> > > <room date="26 Feb 2006"> > > <price type="A">56</price> > > <price type="B">59</price> > > <price type="C">45</price> > > </room> > > <room date="26 Mar 2006"> > > <price type="A">65</price> > > <price type="B">75</price> > > <price type="C">75</price> > > </room> > > </root> > > > > It's not easy sorting out the date format choice that would be better > > changed at source however the restructuring would look like this:- > > > > <?xml version="1.0" encoding="utf-8" ?> > > <xsl:stylesheet version="1.0" > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > <xsl:output method="xml" indent="yes" /> > > <xsl:key name="dates" match="date" use="." /> > > > > <xsl:template match="/root/rooms"> > > <root> > > <xsl:for-each select="*[count(key('dates',date)[1] | ./date) = 1]"> > > <room date="{date}"> > > <xsl:for-each select="key('dates', date)/parent::*"> > > <price band="{substring-after(local-name(),'room')}"> > > <xsl:value-of select="@price" /> > > </price> > > </xsl:for-each> > > </room> > > </xsl:for-each> > > </root> > > </xsl:template> > > > > </xsl:stylesheet> > > > > This assumes that your input really looks like this:- > > > > <root> > > <rooms> > > <roomA price="56"> > > <date>26/02/2006</date> > > </roomA> > > <roomA price="65"> > > <date>26/03/2006</date> > > </roomA> > > <roomB price="59"> > > <date>26/02/2006</date> > > </roomB> > > <roomB price="75"> > > <date>26/03/2006</date> > > </roomB> > > <roomC price="45"> > > <date>26/02/2006</date> > > </roomC> > > <roomC price="75"> > > <date>26/03/2006</date> > > </roomC> > > </rooms> > > </root> > > > > > > Anthony. > > > > > > > > > I tried to do xsl:each-for and doesn't work very well. > > > > > > <?xml version='1.0' ?> > > > <xsl:stylesheet version="1.0" > > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > > <xsl:template match="/"> > > > <xsl:for-each select="root/rooms"> > > > <Root> > > > <xsl:for-each select="roomC"> > > > <xsl:for-each select="../roomB"> > > > <xsl:for-each select="../roomA"> > > > <rooms> > > > <roomsAprice> > > > <xsl:value-of select="."/> > > > </roomsAprice> > > > <roomsBprice> > > > <xsl:value-of select="../roomB"/> > > > </roomsBprice> > > > <roomsCprice> > > > <xsl:value-of select="../roomC"/> > > > </roomsCprice> > > > <Date> > > > <xsl:value-of select="@date"/> > > > </Date> > > > </rooms> > > > </xsl:for-each> > > > </xsl:for-each> > > > </xsl:for-each> > > > </Root> > > > </xsl:for-each> > > > </xsl:template> > > > </xsl:stylesheet> > > > > > > Can someone help me on that? > > > > > > Ina > > > > | ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
