[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Cannot process a result tree fragment as a node-se

Subject: Re: Cannot process a result tree fragment as a node-set under XSLT 1.0 - My alternative don´t function
From: "Alejandro" <alexcontini@xxxxxxxx>
Date: Sun, 13 Apr 2008 12:17:40 +0100
Re:  Cannot process a result tree fragment as a node-se
Thanks you for your help Michael, you have been an invaluable help

It4s correct? I like to process one formulary to search records . I solved so:

/************** XHTML *************/

<form method="post" action="procesar.bsb" id="search">

<input type="text" name="date" id="date" size="14" maxlength="10"/>
<input type="text" name="name" id="name" size="31"/>

<p class="opcion">
<input type="checkbox" name="beca" value="111111" id="beca" />
 <label for="checkbox2">Becas</label></p>

<p class="opcion">
<input type="checkbox" name="conferencia" value="222222" id="checkbox8" />
<label for="checkbox8">Conferencias</label></p>


<p class="opcion">
  <input type="checkbox" name="others" value="" id="others" />
<label for="checkbox10">Others</label></p>
</fieldset>

<p><input type="submit" name="Submit" value="Buscar"  class="boton"/></p>
</form>


/************** XSL *****************



<xsl:param name="name"></xsl:param> <xsl:param name="beca" select="000000"></xsl:param> <xsl:param name="conferencia" select="000000"></xsl:param> <xsl:param name="others" select="000000"></xsl:param>

<xsl:variable name="date" select="20080205000000"></xsl:variable>

<xsl:variable name="filter" select="//RecursoEx1[F_FIN=$date and (CLASIFICACION=$beca or CLASIFICACION=$conferencia or CLASIFICACION=$others) and contains(TITLE,$name)] | //RecursoEx1[F_FIN=$date and (CLASIFICACION=* and $beca=000000 and $conferencia=000000 and $others=000000) and contains(TITLE,$name)]"></xsl:variable>


************* XML ****************



<?xml version="1.0"?> <List>

   <RecursoEx1> <!-- start is the day of the week that the month
       starts. Wednesday in this case -->
       <TITLE>Beca de Sara Baras</TITULO>
       <F_INICIO>20080125000000</F_INICIO>
       <F_FIN>20080211000000</F_FIN>
       <CLASIFICACION>111111</CLASIFICACION>
   </RecursoEx1>


<RecursoEx1> <!-- start is the day of the week that the month starts. Wednesday in this case --> <TITLE>Beca de John</TITULO> <F_INICIO>20080501000000</F_INICIO> <F_FIN>20080205000000</F_FIN> <CLASIFICACION>111111</CLASIFICACION> </RecursoEx1>

   <RecursoEx1>
       <TITLE>Clausura de ..</TITULO>
       <F_INICIO>20080101000000</F_INICIO>
       <F_FIN>20080205000000</F_FIN>
       <CLASIFICACION></CLASIFICACION>
   </RecursoEx1>

   <RecursoEx1>
       <TITLE>Conferencia de ..bla bla bla</TITULO>
       <F_INICIO>20080201000000</F_INICIO>
       <F_FIN>20080205000000</F_FIN>
       <CLASIFICACION>222222</CLASIFICACION>
   </RecursoEx1>

</List>



11:52 13/04/2008
---- Mensaje original ----- De: "Michael Kay" <mike@xxxxxxxxxxxx>
Para: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Enviado: sabado, 12 de abril de 2008 20:03
Asunto: RE: Cannot process a result tree fragment as a node-set under XSLT 1.0 - My alternative don4t function



It's not always possible to get by without using result tree fragments but it is possible in this case. And in general, if you can write

<xsl:variable name="x">
 <xsl:when test="condition1">
   <xsl:copy-of select="exp1"/>
 </xsl:when>
 <xsl:otherwise>
   <xsl:copy-of select="exp2"/>
 </xsl:otherwise>
</xsl:variable>

then you can probably replace it with

<xsl:variable name="x" select="exp1[condition1] | exp2[condition2]"/>

which avoids the cost of copying the nodes, and avoids the RTF problem.

Of course an even better solution is to move to XSLT 2.0.

Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: Alejandro [mailto:alexcontini@xxxxxxxx]
Sent: 12 April 2008 18:50
To: mike@xxxxxxxxxxxx
Cc: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Cannot process a result tree fragment as a
node-set under XSLT 1.0 - My alternative don4t function

Hi Michael,

Thank you so much for the quick response.

Michael >>However, it's not clear to me that you need to
create an RTF in the first place. Why not define $filter as
    <xsl:variable name="filter" select="//RecursoEx1[($option=1 and
F_FIN=$date1 and contains(TITULO,'o')) or ($option=2 and
F_FIN=$date2)]"/>

I want to count the RecursoEx1 elements:
    <p>Number: <xsl:value-of
select="count(exsl:node-set($filter)/RecursoEx1)"/></p> CORRECT!

I want to iterate over the RecursoEx1 elements:
    <xsl:for-each select="exsl:node-set($filter)/RecursoEx1">
CORRECT !

I use xsl:copy-of and exsl:node-set because to error "Cannot
process a result tree fragment as a node-set under XSLT 1.0"
if i code :

<xsl:variable name="filtro">
        <xsl:choose>
            <xsl:when test="$option=1">
                <xsl:copy-of
select="//RecursoEx1[F_FIN=$date1]"/></xsl:when>
            <xsl:otherwise>
                <xsl:copy-of
select="//RecursoEx1[F_FIN=$date2]"/></xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

<p>Number: <xsl:value-of select="$filter"/></p>

    <xsl:for-each select="$filter">
         <p><xsl:value-of select="TITULO"/></p>
    </xsl:for-each>


and i don4t know if exits another posibility. Exists??


The variable "option" is to received from one formulary, but
there are more and then the "filter" will be dynamic.

How can i do to construct the filter dynamic? For example, i
receive one varible named "title" from the formulary with the
value: "John Martin Car Monday" and i like to enumerate the
RecursoEx1 elements that meet with this
condition: TITLE=John or TITLE=Martin or TITLE=Car or TITLE=Monday.

or title variable is Apple Pencil, ..... then the condition
will be TITLE=Apple or TITLE=Pencil

i don4t know how may parameters i will receive in advance..

Thanks again Michael,

Alexander


----- Mensaje original ----- De: "Michael Kay" <mike@xxxxxxxxxxxx> Para: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Enviado: sabado, 12 de abril de 2008 14:03 Asunto: RE: Cannot process a result tree fragment as a node-set under XSLT 1.0 - My alternative don4t function


The node-set returned by the exsl:node-set() function will always contain a single (document or root) node. Perhaps you wanted its children: exsl:node-set()/*.

However, it's not clear to me that you need to create an RTF
in the first place. Why not define $filter as

<xsl:variable name="filter"
   select="//RecursoEx1[($option=1 and F_FIN=$date1 and
contains(TITULO,'o'))
                        or ($option=2 and F_FIN=$date2)]"/>

Note also, that horrible bit of disable-output-escaping can
be avoided by setting the doctype-system and doctype-public
attributes on xsl:output.

Michael Kay
http://www.saxonica.com/


> -----Original Message----- > From: Alejandro [mailto:alexcontini@xxxxxxxx] > Sent: 12 April 2008 13:05 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Cannot process a result tree fragment as a node-set > under XSLT 1.0 - My alternative don4t function > > Hello, i want to recover any records in function of one variable > (option in this case), and i don4t know to do it. I want to print the > TITULO element the those records. > Can you help me, please? > > Cheers, > Alexander > > > ********************************* XML > ************************************* > > <?xml version="1.0"?> > > <List> > <RecursoEx1> > <TITULO>Sara Baras</TITULO> > <F_INICIO>20080125000000</F_INICIO> > <F_FIN>20080211000000</F_FIN> > </RecursoEx1> > > <RecursoEx1> > <TITULO>Exposicion de pintura</TITULO> > <F_INICIO>20080201000000</F_INICIO> > <F_FIN>20080211000000</F_FIN> > </RecursoEx1> > > <RecursoEx1> > <TITULO>Inaguracion de ...</TITULO> > <F_INICIO>20080205000000</F_INICIO> > <F_FIN></F_FIN> > </RecursoEx1> > > <RecursoEx1> > <TITULO>Clausura de ..</TITULO> > <F_INICIO>20080101000000</F_INICIO> > <F_FIN>20080205000000</F_FIN> > </RecursoEx1> > > </List> > > > ********************** XSL ********************** > > <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet > xmlns:i18n="http://apache.org/cocoon/i18n/2.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:exsl="http://exslt.org/common" > extension-element-prefixes="exsl" version="1.0"> > > <xsl:output method="html" media-type="text/html;charset=iso-8859-1" > indent="yes" encoding="ISO-8859-1" omit-xml-declaration="yes" /> > > <xsl:variable name="date1" select="20080205000000"></xsl:variable> > <xsl:variable name="date2" select="20080211000000"></xsl:variable> > <xsl:variable name="option" select="1"></xsl:variable> > > <xsl:template match="/"> > > <xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE > html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">]]></xsl:text> > > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es"> > > <head> > <title>Gabinete of Prensa</title> > <meta http-equiv="Content-Type" content="text/html; > charset=iso-8859-1" > /> > </head> > > <body> > > <xsl:variable name="filter"> > <xsl:choose> > <xsl:when test="$option=1"> > <xsl:copy-of > select="//RecursoEx1[F_FIN=$date1 and > contains(TITULO,'o')]"/></xsl:when> > <xsl:otherwise> > <xsl:copy-of > select="//RecursoEx1[F_FIN=$date2]"/></xsl:otherwise> > </xsl:choose> > </xsl:variable> > > > > > > <p>Number: <xsl:value-of > select="count(exsl:node-set($filter))"/></p> <!-- DON'T FUNCTION --> > > <xsl:for-each select="exsl:node-set($filter)"> > <p><xsl:value-of > select="exsl:node-set($filter)/TITULO"/></p> <!-- > DON'T FUNCTION --> > </xsl:for-each> > > </body> > </html> > </xsl:template> > > </xsl:stylesheet>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.