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: ora:output


Sebastian,

As several people have mailed me on this, I've CC'd the
XSL-List so others might benefit from the example.

Using Oracle XSLT release 2.0.2.8 or later (2.0.2.9 is
the current production release since mid-July 2000), and
given an input document like:

<!-- people.xml -->
<people>
  <person>Steve</person>
  <person>Sebastian</person>
  <person>Nacho</person>
  <person>Michael</person>
</people>

You can use an XSLT stylesheet given at the
bottom of this email -- which uses the <ora:output> built-in 
extension element -- to do the following:

  (1) Output a comma-separated list of all people to the
      default output "resource" using method="text"

  (2) Output odd-numbered people to an HTML file "odd.html"

  (3) Output even-numbered people to indented XML file "even.xml"

Using "oraxsl" to transform people.xml above by the stylesheet...

  $ oraxsl people.xml samplebelow.xsl defaultoutput.txt

below will produce:

  (1) The raw text output "Steve,Sebastian,Nacho,Michael"
      into the file "defaultoutput.txt"

  (2) The file "odd.html" that looks like:

      <html>
        <body>
          <ul>
            <li>Steve</li>
            <li>Nacho</li>
         </ul>
        </body>
      </html>

  (3) The file "even.xml" that looks like:

      <?xml version = '1.0' encoding = 'UTF-8'?>
      <List>
        <Item>Sebastian</Item>
        <Item>Michael</Item>
      </List>

Here's the stylesheet...

<!-- Sample stylesheet using <ora:output> -->
<xsl:stylesheet version="1.0" exclude-result-prefixes="ora"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:ora="http://www.oracle.com/XSL/Transform/java/">

  <!-- NOTE: Trailing slash in "ora" URI above!! -->

  <!-- <xsl:output> controls default output resource's options -->
  <xsl:output method="text"/>

  <!-- 
   | Top-level <ora:output> declares additional output resources
   | 'name' attribute assigns a name to the output resource
   | 'href' attribute provides URI of the file to receive output
   | In addition, <ora:output> supports all attributes of <xsl:output>
   +-->
  <ora:output name="one" href="odd.html" method="html"/>
  <ora:output name="two" href="even.xml"  method="xml" indent="yes"/>

  <xsl:template match="/">
    <!-- No <ora:output use="xxx"> so use default result -->
    <xsl:apply-templates select="people/person" mode="list"/>

    <!--
     | <ora:output use="one"> in a template instantiates
     | its contents such that it will be serialized to
     | the additional output resource named "one" declared above
     +-->
    <ora:output use="one">
      <html>
        <body>
          <ul>
            <xsl:apply-templates select="people/person[position() mod 2 = 1]"/>
          </ul>
        </body>
      </html>
    </ora:output>

    <!--
     | <ora:output use="two"> in a template instantiates
     | its contents such that it will be serialized to
     | the additional output resource named "two" declared above
     +-->
    <ora:output use="two">
      <List>
        <xsl:apply-templates select="people/person[position() mod 2 = 0]"/>
      </List>
    </ora:output>
  </xsl:template>

  <xsl:template match="people/person" mode="list">
    <xsl:value-of select="."/>
    <xsl:if test="not(position()=last())">,</xsl:if>
  </xsl:template>

  <xsl:template match="people/person[position() mod 2 = 1]">
    <li><xsl:value-of select="."/></li>
  </xsl:template>
  <xsl:template match="people/person[position() mod 2 = 0]">
    <Item><xsl:value-of select="."/></Item>
  </xsl:template>

</xsl:stylesheet>
______________________________________________________________
Steve Muench, Lead XML Evangelist & Consulting Product Manager
Business Components for Java & XSQL Servlet Development Teams
Oracle Rep to the W3C XSL Working Group
Author "Building Oracle XML Applications", O'Reilly, Oct 2000
----- Original Message ----- 
From: "Sebastian Rahtz" <sebastian.rahtz@computing-services.oxford.ac.uk>
To: <smuench@us.oracle.com>
Sent: Thursday, July 27, 2000 2:37 AM
Subject: ora:output


| I simply cant make this work. It just echos the ora:output to the
| normal output file. do you have a simple working example?
| 
| sebastian
| 
| 


 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]