Re: [xsl] Dynamic stylesheet selection

Subject: Re: [xsl] Dynamic stylesheet selection
From: Ruben Inoto <ris2@xxxxxxxxx>
Date: Wed, 04 Apr 2001 14:55:47 +0200
> Hi,
>         This is probably a FAQ, but I haven't found the answer (other than
> _no_): is it possible to choose one stylesheet or another based on
> input, or the only way to do that is to choose different modes for a
> template within the same stylesheet?
>

  I don't know if is something like this what you are looking for, maybe it can
help you...

  Here I use an XSL "father" that 'creates' the same XML that has called him, but
with the call to the desired XSL depending on the parameter passed via URL to the
XML. (Don't ask me about performance). Note that I'm using Cocoon...

//Ruben

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

<!-- Variable pasada por parametro via URL al XML (http://fich.xml?imprimir=html)
-->
<xsl:param name="imprimir">0</xsl:param>

<!-- Aplica el template a la raiz del documento XML -->
<xsl:template match="/">

  <!-- Dependiendo de si es para imprimir o no llama a articulo.pdf.xsl -->
  <xsl:choose>
   <xsl:when test="$imprimir='pdf'">
     <xsl:processing-instruction name="xml-stylesheet">
           href="../xsl/articulo.pdf.xsl" type="text/xsl"
     </xsl:processing-instruction>
     <xsl:processing-instruction name="cocoon-process">
          type="xslt"
     </xsl:processing-instruction>
   </xsl:when>

   <xsl:when test="$imprimir='html'">
     <xsl:processing-instruction name="xml-stylesheet">
           href="../xsl/articulo.html.xsl" type="text/xsl"
     </xsl:processing-instruction>
     <xsl:processing-instruction name="cocoon-process">
          type="xslt"
     </xsl:processing-instruction>
   </xsl:when>

   <xsl:otherwise>
     <xsl:processing-instruction name="xml-stylesheet">
           href="../xsl/articulo.capitulos.xsl" type="text/xsl"
     </xsl:processing-instruction>
     <xsl:processing-instruction name="cocoon-process">
          type="xslt"
     </xsl:processing-instruction>
   </xsl:otherwise>
  </xsl:choose>

  <xsl:apply-templates/>

</xsl:template>

<xsl:template match="@*|*|text">
   <xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>
-------------------------------


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread