xsl-list
[Top] [All Lists]

Re: [xsl] Template mode value from param

2011-09-21 07:37:09
Hey Michael,

this is related to my previous thread actually:
http://www.oxygenxml.com/archives/xsl-list/201105/msg00144.html

The situation is like this:
- we have a RDF/SPARQL setup which returns RDF/XML
- default.xsl contains the general page layout and is used as a single
point of entry for all RDF/XML to (X)HTML transforms
- default.xsl imports a bunch of stylesheets like comic_strips.xsl,
maps.xsl, visualizations.xsl which know how to render some specific
RDF/XML types/properties
- the specific stylesheets can be provided by third parties

The problem is that while default.xsl contains the general layout and
specific stylesheets contain layout for separate elements, there is
intermediary layout (navigation etc) which depends on a parameter
($view is the type of currently viewed page) -- and I don't know how
to fit it nicely in here.

I can try to give an example:

default.xsl

  <xsl:import href="comic_strips.xsl"/>
  <xsl:param name="view"/>

  <xsl:template match="/">
    <html>
      <head>...</head>
      <body>
        <!-- header goes here -->
        <!-- insert main content here -->
        <section id="content">
          <xsl:choose>
            <xsl:when test="$view = '&hn;FrontPageView'">
              <xsl:apply-templates select="rdf:RDF" mode="hn:FrontPageView"/>
            </xsl:when>
            <!-- more cases here -->
          <xsl:choose>
        <!-- footer  goes here -->
       </body>
     </html>
  </xsl:template>

comic_strips.xsl:

  <!-- intermediary layout -->
  <xsl:template match="rdf:RDF" mode="hn:FrontPageView">
    <xsl:apply-templates select="key('resources-by-type', '&hn;StripPost')"/>
      <div>
        <!-- some content/navigation here -->
      </div>
  </xsl:template>

  <!-- single item -->
  <xsl:template match="hn:StripPost">   
    <div class="top">
      <h1><a href="{sioc:has_container/@rdf:resource}">Strip</a></h1>
      <!-- some content here -->
    </div>
  </xsl:template>

This is how I currently do it. The xsl:choose with modes feels
backward, I thought there must be better solution, but I couldn't
figure out how/when to apply the intermediary layout template based on
$view value.
Hope this makes sense.

Martynas

On Tue, Sep 20, 2011 at 10:38 AM, Michael Kay <mike(_at_)saxonica(_dot_)com> 
wrote:
On 19/09/2011 19:39, Martynas Jusevicius wrote:

Hey list,

I looked up that template mode is a QName, so I can define and use
modes with prefixes like this:

<xsl:apply-templates select="." mode="hn:BobsLynListView"/>

However I want to make it even more flexible and use a param value like
this:

<xsl:apply-templates select="." mode="{$mode}"/>

Is this possible?

No, this isn't possible.

If you expain the problem you are trying to solve, I'm sure you will get
some ideas for solving it without inventing new language constructs.

Michael Kay
Saxonica

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>