Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] stylesheet for generating html table and aditionally paste calendar data

From: Ragulf Pickaxe <ragulf.pickaxe@--------->
To:
Date: 10/2/2005 8:12:00 PM
Hi Lars,

I haven't seen a reply to this question, so I will try and give it a shot.

> now i want to generate a big html table first wich contains all days of
> the year with the name of the moths as table captions. like this:
>
> | jan | feb| mar| apr| ... | dec|
> ----------------------------
>  1      1     1     1    ...    1
>  ...     ...    ...     ...   ...   ...
> 31    28   31    30   ...   31
>
> (table completely filled). I dont know how to do that. Because, if there
> are only 5 events per moth, the table nevertheless needs to be filled
> with all numbers of the days.
>
> I thought it would be stupid to create this table manually in the
> stylesheet!
>
I would have the following XML in a file, lets call it Months.xml:
<!-- Filename = Months.xml -->
<?xml version="1.0">
<Months>
  <Month><name>jan</name><days>31</days></Month>
  <Month><name>feb</name><days>29</days></Month>
  ...
  <Month><name>dec</name><days>31</days></Month>
</Months>

Then I would be able to generate the html table using the following
simple XSLT (please insert the correct namespace for xslt - I can
never remember it):
<?xml version="1.0">
<xsl:stylesheet xmlns:xsl="...">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:variable name="st" select="document('')"/>
<table>
<tr> <!-- First get the months in 12 columnms (one row) -->
<xsl:for-each select="document('Months.xml')/Months/Month">
  <td><xsl:value-of select="name"/></td>
</xsl:for-each>
</tr>
<!-- Now loop over the dates row (Wendel Piez Method) -->
<xsl:for-each select="($st//node()| $st//@* | $st//namespace::*)
[position() &lt;= 31]"> <!-- Ensure that there are more than 31 items
to loop over -->
  <xsl:variable name="pos" select="position()"/> <!-- position of row -->
  <tr>	<!-- Make one row for each date -->
  <xsl:for-each select="document('Months.xml')/Months/Month">
    <td>  <!-- Now enter the column -->
    <xsl:choose>
      <xsl:when test="$pos&lt;=days"><xsl:value-of select="days"/></xsl:when>
      <xsl:otherwise>&#160;</xsl:otherwise>
    </xsl:choose>
    <!-- (*) See below -->
    </td>
  </xsl:for-each>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>

Now, this should be enough for creating the table that you want.

> the events should then be pasted behind a specific day accoring to the
> .xml source. the second prob ist how can i insert the event at the
> specific place in the table?

Well, to answer this question, you will have to enter additional code.
One solution is to enter the following where (*) is marked in the
stylesheet above:

<xsl:for-each select="/schedule/month[@n=position()]/day[@n=$pos]/date">
  <br/>Time: <xsl:value-of select="@time"/>
  <br/>Event: <xsl:value-of select="event"/>
</xsl:for-each>

This code assumes that schedule is the root element of your input xml.
It selects all date elements that have the same month and the same day
as the current tr and td being filled in the output.

If there are many events, it might be an idea to create a key to hold
the variables (this must be a top-level element in the stylesheet):
<xsl:key name="eventdate-by-month-and-day"
  match="date"
  use="concat(../../@n,'_',../@n)"/>

In this case, the code marked with the asterix (*) will be:
<!-- (Muenchian Method) -->
<xsl:for-each select="$eventdate-by-month-and-day"
use="concat(position(),'_',$pos)">
  <br/>Time: <xsl:value-of select="@time"/>
  <br/>Event: <xsl:value-of select="event"/>
</xsl:for-each>

I hope this helps you. You can, of course, change the output to suit
your solution.
Regards,
Ragulf Pickaxe :-)


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