You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Christian Parpart <tr...@gmx.de> on 2000/10/31 15:03:32 UTC

AW: one XML file but various XSL styles

What do you mean, exactly:

either:

  Your page.xml uses page.xsl for differend
  media-types (IE,Lynx,WAP,...)

or:

  You want to split your page.xsl into two
  or more significant xsl-files like:
  basics.xsl and extensions.xsl are called from pages.xsl

let's go:

  *) for the first, you've to write for each media type
  a single xsl-file. you can include it as follows:

  <?xml version="1.0"?>
  <?xml-stylesheet type="text/xsl" href="page-wap.xsl" media="WAP"?>
  <?xml-stylesheet type="text/xsl" href="page-lynx.xsl" media="Lynx"?>
  <!-- ...go.on... -->

  **) for the second, it's easier as it is. take a look to the
  main page.xsl below:

  <?xml version="1.0">
  <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:include href="basics.xsl"/>
    <xsl:include href="extensions.xsl"/>

    <!-- put your code here -->

  </xsl:stylesheet>


I hope it's really helpfull...

Regards,
Christian Parpart
mailto:cparpart@surakware.com
http://www.surakware.com



-----Ursprungliche Nachricht-----
Von: camille@mandrakesoft.com [mailto:camille@mandrakesoft.com]
Gesendet: Dienstag, 31. Oktober 2000 16:43
An: cocoon-users@xml.apache.org
Betreff: one XML file but various XSL styles


Hi all,

Just installed all the stuff and have been quite impressed by the
product, thanks!

This is my problem: I want to be able to render a single XML file with
differents XSL stylesheets. What solution is generally used, is it
possible to do that without passing through a wrapper that would add the
<?xml-stylesheet> directive in the header of the file before processing?

Thanks, Camille.

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


RE: AW: one XML file but various XSL styles

Posted by Kirk Woerner <ki...@stoneseeker.com>.
Yes, I changed it a bit from what I had... sorry bout that.  I was using
someones XSL for simply going from a print xsl to an html XSL and I thought
I could make it general on the fly (guess not :)

This is not my code.  It's been posted to this list before (unfortunately I
can't remember who).  One thing I had to remember when I used it is the
processing instructions for the xinclude as well.  Even if they are in the
original XML file, it won't get processed unless  it's there. Or at least,
it didn't for me (which is why it was there)

Given that you got it to work though, maybe it can be put into the FAQ now
as another option.  Robin asked for a clear patch and I guess this would be
it.  It's below again (without the xinclude).  Thanks

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

  <xsl:param name="style"/>
    <xsl:template match="/">
      <xsl:choose>
        <!-- when style is specified -->
        <xsl:when test="$style">
          <xsl:processing-instruction name="xml-stylesheet">
            href="<xsl:value-of select="$style"/>" type="text/xsl"
          </xsl:processing-instruction>
          <xsl:processing-instruction name="cocoon-process">
            type="xslt"
          </xsl:processing-instruction>
        </xsl:when>
        <!-- Otherwise use default.xsl -->
        <xsl:otherwise>
          <xsl:processing-instruction name="xml-stylesheet">
            href="default.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>

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

</xsl:stylesheet>

>-----Original Message-----
>From: Davor Cengija [mailto:dcengija@mcs.hr]
>Sent: Tuesday, October 31, 2000 2:06 PM
>To: cocoon-users@xml.apache.org
>Subject: RE: AW: one XML file but various XSL styles
>
>
>	Hi Kirk and everybody...
>
>On Tue, 31 Oct 2000, Kirk Woerner wrote:
>
>>You can also do it by including whichever stylesheet you want
>>This really ought to be in the fact as well as the XSP method shown I
>>think...
>>
>
>	This solution helped me a lot, as well. I asume you typed it
>	directly, since it has some minor mistakes...
>
>>
>><a href="chapter.xml?style=full.xsl">show full</a>
>>
>>chapter.xml:
>><?xml-stylesheet href="style.xsl" type="text/xsl"?>
>
><?cocoon-process type="xslt"?> is needed here.
>
>>style.xsl
>><?xml version="1.0"?>
>><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>version="1.0">
>>
>><!-- this is internal reference to the "style=" in the url -->
>> <xsl:param name="style"/>
>>
>> <xsl:template match="/">
>>  <xsl:choose>
>>   <!-- when "style" is specified ... -->
>>   <xsl:when test="$style">
>>    <xsl:variable name="href">/stylesheets/<xsl:value-of
>>select="$style"></xsl:variable>
>
><xsl:value-of select="$style"/>  <-- missing closing slash -->
>
>	However, I don't understand do we actually need xsl:variable
>	here?
>
>>    <xsl:processing-instruction name="xml-stylesheet">
>>       href="$style" type="text/xsl"
>
>	This doesn't work (at least not in Cocoon 1.8). It complains
>	about not finding /path/$style file ($style is not expanded).
>	The solution is to have this:
>
>href="<xsl:value-of select="$style"/>"
>
>
>	The rest is OK. Here's the .xsl which I use:
>
>
><?xml version="1.0"?>
><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>version="1.0">
>
><xsl:param name="style"/>
>
>	<xsl:template match="/">
>	 <xsl:choose>
>	  <!-- when style is specified -->
>	  <xsl:when test="$style">
>	   <!-- xsl:variable name="href"><xsl:value-of
>select="$style"/></xsl:variable -->
>	   <xsl:processing-instruction name="xml-stylesheet">
>	    href="<xsl:value-of select="$style"/>" type="text/xsl"
>	   </xsl:processing-instruction>
>	   <xsl:processing-instruction name="cocoon-process">
>	    type="xinclude"
>	   </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="stylepdf.xsl" type="text/xsl"
>		</xsl:processing-instruction>
>	   <xsl:processing-instruction name="cocoon-process">
>	    type="xinclude"
>	   </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>
>
>--
>      v
>Davor Cengija
>dcengija@mcs.hr
>===========================
>"Nicht mit Alkohol mischen"
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
>For additional commands, e-mail: cocoon-users-help@xml.apache.org
>


RE: AW: one XML file but various XSL styles

Posted by Davor Cengija <dc...@mcs.hr>.
	Hi Kirk and everybody...

On Tue, 31 Oct 2000, Kirk Woerner wrote:

>You can also do it by including whichever stylesheet you want
>This really ought to be in the fact as well as the XSP method shown I
>think...
>

	This solution helped me a lot, as well. I asume you typed it
	directly, since it has some minor mistakes...

>
><a href="chapter.xml?style=full.xsl">show full</a>
>
>chapter.xml:
><?xml-stylesheet href="style.xsl" type="text/xsl"?>

<?cocoon-process type="xslt"?> is needed here.

>style.xsl
><?xml version="1.0"?>
><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>version="1.0">
>
><!-- this is internal reference to the "style=" in the url -->
> <xsl:param name="style"/>
>
> <xsl:template match="/">
>  <xsl:choose>
>   <!-- when "style" is specified ... -->
>   <xsl:when test="$style">
>    <xsl:variable name="href">/stylesheets/<xsl:value-of
>select="$style"></xsl:variable>

<xsl:value-of select="$style"/>  <-- missing closing slash -->

	However, I don't understand do we actually need xsl:variable
	here?

>    <xsl:processing-instruction name="xml-stylesheet">
>       href="$style" type="text/xsl"

	This doesn't work (at least not in Cocoon 1.8). It complains
	about not finding /path/$style file ($style is not expanded).
	The solution is to have this:

href="<xsl:value-of select="$style"/>"


	The rest is OK. Here's the .xsl which I use:


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

<xsl:param name="style"/>

	<xsl:template match="/">
	 <xsl:choose>
	  <!-- when style is specified -->
	  <xsl:when test="$style">
	   <!-- xsl:variable name="href"><xsl:value-of select="$style"/></xsl:variable -->
	   <xsl:processing-instruction name="xml-stylesheet">
	    href="<xsl:value-of select="$style"/>" type="text/xsl"
	   </xsl:processing-instruction>
	   <xsl:processing-instruction name="cocoon-process">
	    type="xinclude"
	   </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="stylepdf.xsl" type="text/xsl"
		</xsl:processing-instruction>
	   <xsl:processing-instruction name="cocoon-process">
	    type="xinclude"
	   </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>

-- 
      v
Davor Cengija
dcengija@mcs.hr
===========================
"Nicht mit Alkohol mischen"


RE: AW: one XML file but various XSL styles

Posted by Kirk Woerner <ki...@stoneseeker.com>.
You can also do it by including whichever stylesheet you want
This really ought to be in the fact as well as the XSP method shown I
think...


<a href="chapter.xml?style=full.xsl">show full</a>

chapter.xml:
<?xml-stylesheet href="style.xsl" type="text/xsl"?>

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

<!-- this is internal reference to the "style=" in the url -->
 <xsl:param name="style"/>

 <xsl:template match="/">
  <xsl:choose>
   <!-- when "style" is specified ... -->
   <xsl:when test="$style">
    <xsl:variable name="href">/stylesheets/<xsl:value-of
select="$style"></xsl:variable>
    <xsl:processing-instruction name="xml-stylesheet">
       href="$style" type="text/xsl"
    </xsl:processing-instruction>
    <xsl:processing-instruction name="cocoon-process">
       type="xinclude"
    </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="/stylesheets/default.xsl" type="text/xsl"
    </xsl:processing-instruction>
    <xsl:processing-instruction name="cocoon-process">
       type="xinclude"
    </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>



>-----Original Message-----
>From: T.Pospisek's MailLists [mailto:tpo2@spin.ch]
>Sent: Tuesday, October 31, 2000 7:43 AM
>To: cocoon-users@xml.apache.org
>Subject: Re: AW: one XML file but various XSL styles
>
>
>On Tue, 31 Oct 2000 camille@mandrakesoft.com wrote:
>
>> Thanks for the answer, but my case is indeed different from those two.
>> Here is a trivial example: my XML file: chapter.xml, holds various
>> sections containing each one abstract and various paragraphs.
>>
>> The user is offered the ability to view either the full chapter content
>> or just the abstracts.
>> Both HTML pages are obtained obviously from the same chapter.xml file,
>> but using quite different stylesheets.
>>
>> How can I do that.
>
>query page:
>
>Dear user, chose either the the <a href="show.xml&view=full">full</a>
>or <a href="show.xml&view=partial">partial</a> view of the chapter.
>
>chapter.xml:
><?xml-stylesheet href="show.xsl" type="text/xsl"?>
>
>show.xsl:
>
><xsl:if test="$param=full">
> ...
>
>You have to study the details on passing and checking parameters,
>since I haven't used that feature yet, but I think it should be
>clear what I mean.
>
>Does this solve your problem?
>*t
>
>-------------------------------------------------------------------
>---------
>             Tomas Pospisek
>	     SourcePole   -  Linux & Open Source Solutions
>	     http://sourcepole.ch
>	     Elestastrasse 18, 7310 Bad Ragaz, Switzerland
>	     Tel: +41 (81) 330 77 11
>-------------------------------------------------------------------
>---------
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
>For additional commands, e-mail: cocoon-users-help@xml.apache.org
>


Re: AW: one XML file but various XSL styles

Posted by "T.Pospisek's MailLists" <tp...@spin.ch>.
On Tue, 31 Oct 2000, T.Pospisek's MailLists wrote:

> Dear user, chose either the the <a href="show.xml&view=full">full</a>

Oops, that should be show.xml?view=full
*t

----------------------------------------------------------------------------
             Tomas Pospisek
	     SourcePole   -  Linux & Open Source Solutions
	     http://sourcepole.ch
	     Elestastrasse 18, 7310 Bad Ragaz, Switzerland
	     Tel: +41 (81) 330 77 11
----------------------------------------------------------------------------


Re: AW: one XML file but various XSL styles

Posted by "T.Pospisek's MailLists" <tp...@spin.ch>.
On Tue, 31 Oct 2000 camille@mandrakesoft.com wrote:

> Thanks for the answer, but my case is indeed different from those two.
> Here is a trivial example: my XML file: chapter.xml, holds various
> sections containing each one abstract and various paragraphs.
> 
> The user is offered the ability to view either the full chapter content
> or just the abstracts.
> Both HTML pages are obtained obviously from the same chapter.xml file,
> but using quite different stylesheets.
> 
> How can I do that.

query page:

Dear user, chose either the the <a href="show.xml&view=full">full</a>
or <a href="show.xml&view=partial">partial</a> view of the chapter.

chapter.xml:
<?xml-stylesheet href="show.xsl" type="text/xsl"?>

show.xsl:

<xsl:if test="$param=full">
 ...

You have to study the details on passing and checking parameters,
since I haven't used that feature yet, but I think it should be
clear what I mean.

Does this solve your problem?
*t

----------------------------------------------------------------------------
             Tomas Pospisek
	     SourcePole   -  Linux & Open Source Solutions
	     http://sourcepole.ch
	     Elestastrasse 18, 7310 Bad Ragaz, Switzerland
	     Tel: +41 (81) 330 77 11
----------------------------------------------------------------------------


Re: AW: one XML file but various XSL styles

Posted by ca...@mandrakesoft.com.
Christian Parpart a écrit :
> 
> What do you mean, exactly:
> 
> either:
> 
>   Your page.xml uses page.xsl for differend
>   media-types (IE,Lynx,WAP,...)
> 
> or:
> 
>   You want to split your page.xsl into two
>   or more significant xsl-files like:
>   basics.xsl and extensions.xsl are called from pages.xsl

Thanks for the answer, but my case is indeed different from those two.
Here is a trivial example: my XML file: chapter.xml, holds various
sections containing each one abstract and various paragraphs.

The user is offered the ability to view either the full chapter content
or just the abstracts.
Both HTML pages are obtained obviously from the same chapter.xml file,
but using quite different stylesheets.

How can I do that.

Camille.