Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: triple xsl:for-each problem? Please any suggestion

From: "ina" <roberta.inalbon@-----.--->
To: NULL
Date: 7/12/2006 11:55:00 PM

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!

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
> >



transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent