Re: func:function and func:result

Tamer Demirel <[email protected]> Mon, 23 Nov 2009 14:26:47 +0100
Newsgroups gmane.text.xml.xslt.extensions
Message-ID <[email protected]>
Thank you very much. Thats what i need.
I have to do it in XSLT 1.0.

Cheers,
Tamer


Hermann Stamm-Wilbrandt schrieb:
> Hello,
>
> you just need two changes:
> - enclose the generated output by <func:result>...</func:result> (that is
> what func:result is intended for)
> - use xsl:copy-of to retrieve the result.
>
> That's is (find it at bottom), just works under xalan 2.7.1 and DataPower
> compiler.:
>
> [stammw@br8ggx73 xalan-j_2_7_1]$ java -jar xalan.jar -IN some.xml -XSL
> genexslt.xsl ; echo
> <?xml version="1.0" encoding="UTF-8"?><INVOIC_TYPE><xsl:if
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" test="string-length
> ($invoic_type)&gt;0"><xsl:value-of select="$invoic_type_final"/>
> </xsl:if></INVOIC_TYPE>
> [stammw@br8ggx73 xalan-j_2_7_1]$
>
> Saxon has a problem with it:
> C:\saxon>java -jar saxon9.jar a.xml genexslt.xsl
> Warning: at xsl:stylesheet on line 5 column 19 of genexslt.xsl:
>   Running an XSLT 1.0 stylesheet with an XSLT 2.0 processor
> Error on line 30 of genexslt.xsl:
>   Cannot find a matching 3-argument function named
> {http://exslt.org/functions/m.
> y}getElement()
> Transformation failed: Run-time errors were reported
>
> C:\saxon>
>
> ==========================================================
> <xsl:stylesheet
>     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>     xmlns:func="http://exslt.org/functions"
>     xmlns:my="http://xslt.org/functions/my"
>     version="1.0">
>
>
>     <func:function name="my:getElement">
>         <xsl:param name="variableName"/>
>         <xsl:param name="variableName_final"/>
>         <xsl:param name="elementName"/>
>         <func:result>
>         <xsl:element name="{$elementName}">
>             <xsl:element name="xsl:if">
>                 <xsl:attribute
> name="test"><xsl:text>string-length($</xsl:text><xsl:value-of
> select="$variableName"/><xsl:text>)>0</xsl:text></xsl:attribute>
>                 <xsl:element name="xsl:value-of">
>                     <xsl:attribute
> name="select"><xsl:text>$</xsl:text><xsl:value-of
> select="$variableName_final"/></xsl:attribute>
>                 </xsl:element>
>             </xsl:element>
>         </xsl:element>
>         </func:result>
>     </func:function>
>
>     <xsl:template match="/">
>     <xsl:copy-of
>     select="my:getElement('invoic_type','invoic_type_final','INVOIC_TYPE')"/>
>     </xsl:template>
> </xsl:stylesheet>
>
>
> Mit besten Gruessen / Best wishes,
>
> Hermann Stamm-Wilbrandt
> Developer, XML Compiler
> WebSphere DataPower SOA Appliances
> ----------------------------------------------------------------------
> IBM Deutschland Research & Development GmbH
> Vorsitzender des Aufsichtsrats: Martin Jetter
> Geschaeftsfuehrung: Dirk Wittkopp
> Sitz der Gesellschaft: Boeblingen
> Registergericht: Amtsgericht Stuttgart, HRB 243294
>
>
>                                                                            
>              Tamer Demirel                                                 
>              <[email protected]                                             
>              e>                                                         To 
>              Sent by:                  [email protected]         
>              exslt-bounces@lis                                          cc 
>              ts.fourthought.co                                             
>              m                                                     Subject 
>                                        [exslt] func:function and           
>                                        func:result                         
>              11/21/2009 05:31                                              
>              PM                                                            
>                                                                            
>                                                                            
>                                                                            
>                                                                            
>
>
>
>
> Hallo,
>
> i am using Xalan 2.7.1 and exslt.
> I habe Problems with func:result.
>
> I want to have as result a part of xslt code.
>
> My Example:
>
> Function:
>     <func:function name="my:getElement">
>         <xsl:param name="variableName"/>
>         <xsl:param name="variableName_final"/>
>         <xsl:param name="elementName"/>
>         <xsl:element name="{$elementName}">
>             <xsl:element name="xsl:if">
>                 <xsl:attribute
> name="test"><xsl:text>string-length($</xsl:text><xsl:value-of
> select="$variableName"/><xsl:text>)>0</xsl:text></xsl:attribute>
>                 <xsl:element name="xsl:value-of">
>                     <xsl:attribute
> name="select"><xsl:text>$</xsl:text><xsl:value-of
> select="$variableName_final"/></xsl:attribute>
>                 </xsl:element>
>             </xsl:element>
>         </xsl:element>
>         <func:result/>
>     </func:function>
>
> Call of the Function:
> <xsl:value-of
> select="my:getElement('invoic_type','invoic_type_final','INVOIC_TYPE')"/>
>
> I get the failure:
> misplaced literal result in a func:function container.
>
> But it works for me.
>
> This doesnt work:
>
>     <func:function name="my:getElement">
>         <xsl:param name="variableName"/>
>         <xsl:param name="variableName_final"/>
>         <xsl:param name="elementName"/>
>         <func:result>
>         <xsl:element name="{$elementName}">
>             <xsl:element name="xsl:if">
>                 <xsl:attribute
> name="test"><xsl:text>string-length($</xsl:text><xsl:value-of
> select="$variableName"/><xsl:text>)>0</xsl:text></xsl:attribute>
>                 <xsl:element name="xsl:value-of">
>                     <xsl:attribute
> name="select"><xsl:text>$</xsl:text><xsl:value-of
> select="$variableName_final"/></xsl:attribute>
>                 </xsl:element>
>             </xsl:element>
>         </xsl:element>
>         </func:result>
>     </func:function>
>
> Do somebody know, what i can do to fix the problem? Maybe older version
> helps?
> Thx,
> Tamer
>
> _______________________________________________
> exslt mailing list
> [email protected]
> http://www.exslt.org/list
>
>
>