Kevin,

there are many ways of doing what you want to do, outside of modifying your
code as has already been suggested.

You can generate Cocoon processing instructions dynamically in your XML,
using the <xsp:pi> tag (see http://xml.apache.org/cocoon/xsp.html for
instructions on this.)  You can also chain stylesheets using the
<xsl:processing-instruction> tag, which is how I prefer to do it.

You can grab your request parameters (mode=view, etc.) either by using XSP
in your object.xml or using <xsl:param name="mode"/> at the root level of
your stylesheet (see "Using query parameters during XSL transformation" in
http://xml.apache.org/cocoon/guide.html for more info on that.)

For simplicity, let's assume your XML looks like this (either a static XML
file or the output from your XSP page):

<page>
  <mode>view</mode>
  <stuff>...</stuff>
</page>

Your stylesheet would look like this:

<xsl:template match="/page">
  <xsl:processing-instruction name="cocoon-process">
      type="xslt"
  </xsl:processing-instruction>

  <xsl:choose>
    <xsl:when test="mode='view'">
      <xsl:processing-instruction name="xml-stylesheet">
        href="view.xsl"
        type="text/xsl"
      </xsl:processing-instruction>
    </xsl:when>

    <xsl:when test="mode='edit'">
      <xsl:processing-instruction name="xml-stylesheet">
        href="edit.xsl"
        type="text/xsl"
      </xsl:processing-instruction>
    </xsl:when>
  </xsl:choose>

  <xsl:apply-templates select="stuff"/>
</xsl:template>

...

-Christopher




Please respond to [EMAIL PROTECTED]

To:   <[EMAIL PROTECTED]>
cc:

Subject:  Dynamic stylesheets (Newbie question)


I currently have two XML documents, object-view.xml and object-edit.xml.
Both are identical except for one word in one line.

object-view.xml calls this stylesheet:
<?xml-stylesheet type="text/xsl" href="view.xsl"?>

while object-edit.xml calls this one:
<?xml-stylesheet type="text/xsl" href="edit.xsl"?>

It seems silly and inefficient to have two XML documents for this.  What I
want to do is have just one XML file and access these two different
renditions like this (or some other easy method):

http://servername:8080/cocoon/object.xml?mode=view
http://servername:8080/cocoon/object.xml?mode=edit

I am surprised I cannot find an answer to this problem.  I learned that
XML/XSLT can't do this alone, and then I figured Cocoon can do this, but I
have searched FAQ, archive and docs.  Am I not looking in the right place
or
using the proper terms?  Any pointers appreciated.  I've got 1.8.2
installed
with Jakarta Tomcat 3.2.3.

Thanks,

--Kevin





---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>

Reply via email to