You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Chris Gow <cg...@digitalfairway.com> on 2001/02/12 15:40:50 UTC

problems with the xalan nodeset extenstion function in Cocoon

Hi All:

I am having a problem getting Cocoon to transform a stylesheet that 
converts two XSL variables into a nodeset (using the xalan built-in nodeset 
function) and comparing them.  Below are my XML and XSL files.  I don't 
think this is a Xalan problem because running them against the 
org.apache.xalan.xslt.Process class the transformation worked.  I tested 
this against the command line version of Cocoon 1.8.2.   The error that I 
am getting is: "Attribute child does not have an owner document 
element!".  If anybody could shed some light on this I would really 
appreciate it.  I have already come up with a more programmatic solution, 
but 1) I don't like it (not very XPathish) 2) Am curious to know why this 
doesn't work in Cocoon.

I apologize for sending a large email to the list.

Thanks

Chris

========TEST.XML========
<?xml version="1.0"?>

<?xml-stylesheet href="test.xsl" type="text/xsl"?>
<?cocoon-process type="xslt"?>

<page>
   <options>
     <option value="a">a</option>
          <option value="b">b</option>
          <option value="c">c</option>
          <option value="d">d</option>
          <option value="elf">e</option>
     <option value="f">f</option>
   </options>

   <selected>
     <option value="b">b</option>
     <option value="c">c</option>
   </selected>

</page>
======END TEST XML======

========TEST.XSL========
<?xml version="1.0"?>

<xsl:stylesheet  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xalan-nodeset="org.apache.xalan.xslt.extensions.Nodeset"
 >

<!-- create two select boxes.  The first is created using data supplied
      from the XML file, the second one uses the xalan nodeset( ) extension
      function to convert our parameters into nodesets.  This is to illustrate
      that the xpath query works as expected (values that appear in both 
options
      and selected have the 'selected' attribute set).
-->
<xsl:template match="/">
   <html>
   <head/>
   <body>
     <form>
      <!-- uncomment out below to see what is supposed to happen when it
            works
       -->
       <!--<select name="fromXML" size="6" multiple="/">
         <xsl:call-template name="TestViaXML"/>
       </select>-->

       <select name="foo" size="6" multiple="/">
         <xsl:call-template name="TestCreateNodeSet">
           <xsl:with-param name="options">
             <option value="alf">A</option>
             <option value="bar">B</option>
             <option value="cat">C</option>
             <option value="dog">D</option>
             <option value="elf">E</option>
             <option value="foo">F</option>
           </xsl:with-param>

           <xsl:with-param name="selected">
             <option value="cat"/>
             <option value="elf"/>
           </xsl:with-param>
         </xsl:call-template>

       </select>
     </form>
   </body>
   </html>
</xsl:template>

<!-- This template gets its option data from the XML file and looks to see
      if a matching selected value is found.  If so, add the selected 
attribute to
      the resulting option element
-->
<xsl:template name="TestViaXML">
   <xsl:for-each select="/page/options/*">
     <xsl:element name="option">
       <xsl:attribute name="value"><xsl:value-of 
select="@value"/></xsl:attribute>
       <xsl:if test="@value=/page/selected/*/@value">
         <xsl:attribute name="selected"/>
       </xsl:if>
     </xsl:element>
   </xsl:for-each>
</xsl:template>


<xsl:template name="TestCreateNodeSet">
   <xsl:param name="options"/>
   <xsl:param name="selected"/>

   <xsl:for-each select="xalan-nodeset:nodeset($options)/*">
     <xsl:element name="option">
       <xsl:attribute name="value"><xsl:value-of 
select="@value"/></xsl:attribute>
       <xsl:if test="@value=xalan-nodeset:nodeset($selected)/*/@value">
         <xsl:attribute name="selected"/>
       </xsl:if>
       <!--<xsl:variable name="foo"><xsl:value-of 
select="@value"/></xsl:variable>
       <xsl:for-each select="xalan-nodeset:nodeset($selected)/*">
         <xsl:if test="@value=$foo">
           <xsl:attribute name="selected"/>
         </xsl:if>
       </xsl:for-each>
      -->
     </xsl:element>
   </xsl:for-each>
</xsl:template>
</xsl:stylesheet>
======END TEST XSL======