This Time Self-Hosted
dark mode light mode Search

New site style… XSL help, please :)

Okay, I wanted to blog about that yesterday, but I ended up the site restyle at 4am and also if I was able to sleep only at 6am, I wasn’t going to blog with that insomnia. I wish to thank haran who doesn’t know me 😉 He wrote some of the most beautiful webdesigns for OSWD, and are his most of the ones I used for my site (and its one of his heavy elaborated the one used for Ziotto website -note: it’s an Italian crazy and fun site of some friends of mine, and me, too :P-).

This time using XSL I was able to abstract most of the work so that I just had to change a base template file to do most of the job, but I still have some problems with XSL that I want to nail down, for who wants to help me, in the second page I’ll show what I’m trying to do and does not work as I expected.. if you’re an XSL expert, please help me :‘)

With the main template that renders the base page list, I have also a template that designs the “blocks” of the site (the box you see with content). They are declared this way:

<!-- simple block -->
<xsl:template name="block" match="block">
  <xsl:param name="id" select="@id" />
  <xsl:param name="title" select="@title" />
  <xsl:param name="content" select="./" />

  <xhtml:div class="darkerBox">
    <xsl:attribute name="id"><xsl:value-of select="$id" /></xsl:attribute>
    <xhtml:h1><xsl:value-of select="$title" /></xhtml:h1>
    <xsl:apply-templates select="$content" />

    <xhtml:br />
  </xhtml:div>
</xsl:template>

Originally, I just used a matching template for <block> tags and then repeated the <div> thing on every page, but that was not fine as I had to change all the stylesheets every time I changed template.
With the params, I can just call the named template so for example to get articles I use:

<xsl:template match="articles">
  <xsl:call-template name="block">
    <xsl:with-param name="id">articles</xsl:with-param>
    <xsl:with-param name="title">Articles' list</xsl:with-param>
    <xsl:with-param name="content" select="./" />
  </xsl:call-template>
</xsl:template>

and that works fine, as far as the <articles> tag contains block-like formatting.

For the downloads page instead I wanted to do something different, and having the content parameter be created not only by templates:

<xsl:with-param name="content">
  <xhtml:ul>
    <xsl:apply-templates />
  </xhtml:ul>
</xsl:with-param>

but this does not work at all.

Am I missing something basic here? Every suggestion is welcome 🙂

Comments 2
  1. I think I understand what you are trying to do. However I don’t think it will work.In the normal case you are passing an xpath to use in a select. In the downloads case you are trying to pass a nodeset or some text or something.I think there is an extension function that will do some of what you want. Which is basically evaluate either to a nodeset from a nodeset or an xpath. Then you’d pass that as a parameter (I don’t know if that will work either). I think its commonly called eval() (or something similar.) Its probably in esxlt standard?The better way to do it is to subtemplate and pass the template to use for the insides of the box as another parameter.so in the box template instead of doing…you do: You’d then pass the name of a template to use for the insides of the box.I think that would work, and give even more flexibility. However its been a long time since I did much in the way of xslt.

  2. Ah crap… it stripped all the code…Basically what you do it is you replate the apply-templates in the box fragment with a call-template that calls a template you passed as a parameter.so:[xsl:template name=”box”] …. open box stuff …. [xsl:call-template name=”$content_template”] [xsl:with-param name=”content”] [xsl:value-of select=”$content”/] [/xsl:with-template] [/xsl:call-template] …. close box stuff ….[/xsl:template]I hope this is readable…

Leave a Reply to Colin LearCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.