Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Getting context between nodes >Thread Next - Re: Getting context between nodes Re: Getting context between nodesTo: 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(.,'
')"/>
<xsl:for-each select="key('kJobs', .)">
<xsl:value-of select="concat(' ',.,'
')"/>
</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
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
