This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: one XML file, two XSLT style sheets


According to your explanations (processing-instructions) I assume that you
want to use Cocoon 1. But I must point out, that there is Cocoon 2 - better,
easier and very stable, although it's still in beta-status. But this Beta 2
is more stable than MS-products after SP 2 - my tutor said it. And my
experiences with it are very good too. I work on such a system.

With Cocoon 2 it's very easy to realize your wish. You have a Sitemap in
Cocoon 2, where something like the following can be written.

<map:match pattern="mypage.summary">
    <map:generate src="mypage.xml"/>
    <map:transform src="summary.xsl"/>
    <map:serialize type="html"/>
</map:match>

<map:match pattern="mypage.detail">
    <map:generate src="mypage.xml"/>
    <map:transform src="detail.xsl"/>
    <map:serialize type="html"/>
</map:match>

Another version using the wildcard-matcher does the same:

<map:match pattern="mypage.*">
    <map:generate src="mypage.xml"/>
    <map:transform src="{1}.xsl"/>
    <map:serialize type="html"/>
</map:match>

Also you can give parameters to a stylesheet or do multiple transformations:

<map:match pattern="mypage.*">
    <map:generate src="mypage.xml"/>
    <map:transform src="{1}.xsl"/>
    <map:transform src="another.xsl">
        <map:param name="anything" value="test"/>
    </map:transform>
    <map:serialize type="html"/>
</map:match>

The value for the parameter can be something from the URL too.

These are only the most important facts. You can do much more like
browser-identification (without javascript!!) or something else basing on
the information of the request-header. For more information
http://xml.apache.org/cocoon2/index.html.

Hope this helps a bit,

Joerg


----- Original Message -----
From: "Ines Robbers" <conceptMe@web.de>
To: <XSL-List@lists.mulberrytech.com>
Sent: Thursday, September 20, 2001 9:35 PM
Subject: [xsl] one XML file, two XSLT style sheets


> dear list,
>
> this is for my final project which i have to hand in tomorrow... urgh. if
anyone could help me with this problem i'd be utterly greatful!!!
>
> background info: i am working on cocoon, want to build an xml website and
am looking for a server-side solution for the following problem:
>
> problem: you have one xml file with say a list of
> <item>
> </title>
> <moreinfo/>
> </item>
> <item>
> </title>
> <moreinfo/>
> </item>
> ...
> now, on one webpage you only want to display the titles (with summary.xsl)
which are links and lead to a new page that display the detailed information
(with detail.xsl) of that requested item. how do you switch between your two
stylesheets? how do you link from one version of the xml file to the other
version of that same xml file?
>
> apparent crystal clear solution from my tutor which i don't understand at
all:
>
> "The way I have delt with this in the past, is to have 3 stylesheets
>
> The first one (refered to from your XML file) chooses which of the other
> two to do the job, depending on some input parameter.
>
> This is a template snippet that does this trick.
>
> <!--
>
>   <xsl:template match="doc">
>       <xsl:variable name="style">
>           <xsl:choose>
>         <xsl:when test=" $as != '' "><xsl:value-of
select="$as"/></xsl:when>
>               <xsl:otherwise><xsl:value-of
select="@style"/></xsl:otherwise>
>           </xsl:choose>
>       </xsl:variable>
>       <xsl:processing-instruction
> name="xml-stylesheet">href="/stylesheet/<xsl:value-of
> select="$style"/>.xsl" type="text/xsl"</xsl:processing-instruction>
>       <xsl:processing-instruction
> name="cocoon-process">type="xslt"</xsl:processing-instruction>
> <doc>
>           <!-- templates to copy all the document -->
>       </doc>
>   </xsl:template>
>
> -->
>
> It sets up a variable called $style, either from the contents of the 'as'
> request parameter ie. 'mypage.xml?as=list', or from the 'style' attribute
> of the document being processed (acts as the default).
>
> Next the StyleSheet generates a 'processing instruction' telling the
cocoon
> processor to transform the output of this StyleSheet with another. Your
> first StyleSheet then should copy over all that the subsequent StyleSheets
> require for their job."
>
> i have just really started on xml and don't understand how something works
before i have seen it work - well, if that makes any sense. so maybe, if
someone has the nerves and time, could i possibly send them my files because
i just don't know how to integrate this solution into my particular case.
>
> many thanks and kind regards,
>
> ines


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]