Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Getting context between nodes

From: "Dimitre Novatchev" <dimitren@---.---.-->
To: NULL
Date: 6/3/2005 7:10:00 PM
"urug haiml" <taisto69@h...> wrote in message 
news:OP7aPeAaFHA.612@T......
> Hello
>
> I have a problem with my xsl-transforming because my xml-data is not well
> structured. Unfortunately it cant be changed. My data looks like this:
>
> <schedule>
>    <day>monday</day>
>    <job>dishes</job>
>    <job>clean</job>
>    <job>...</job>
>    <day>Tuesday</day>
>    <job>wipe</job>
>    <job>....</job>
>    <day>Wednesday</job>
>    <job>...</job>
>    ....
> </schedule>
>
> Is there a way to pick jobs, for example monday from between the day-tags
> monday & tuesday.

This transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <xsl:output method="text"/>

  <xsl:key name="kJobs" match="job" use="preceding-sibling::day[1]"/>

 <xsl:template match="/">
   <xsl:for-each select="*/day">
     <xsl:value-of select="concat(.,'&#xA;')"/>
     <xsl:for-each select="key('kJobs', .)">
       <xsl:value-of select="concat('  ',.,'&#xA;')"/>
     </xsl:for-each>
   </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>

when applied to the following source.xml:

<schedule>
    <day>monday</day>
    <job>dishes</job>
    <job>clean</job>
    <job>learn</job>
    <day>Tuesday</day>
    <job>wipe</job>
    <job>task22</job>
    <day>Wednesday</day>
    <job>task31</job>
    <job>task32</job>
    <day>Thursday</day>
    <job>task41</job>
    <job>task42</job>
    <day>Friday</day>
    <job>task51</job>
    <job>task52</job>
    <day>Saturday</day>
    <job>task61</job>
    <job>task62</job>
    <day>Sunday</day>
    <job>task71</job>
    <job>task72</job>
</schedule>

produces the wanted result:

monday
  dishes
  clean
  learn
Tuesday
  wipe
  task22
Wednesday
  task31
  task32
Thursday
  task41
  task42
Friday
  task51
  task52
Saturday
  task61
  task62
Sunday
  task71
  task72


Hope this helped.

Cheers,
Dimitre Novatchev




transparent
Print
Mail
Like It
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