You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Fausto <ch...@gmail.com> on 2008/10/24 14:35:42 UTC

Java extensions namespaces

Hi all,

I am not sure I did understand well how the extension namespaces works on
xalan-j, because I have not found a way to define my own namespace for the
extentions.

Like having "http://my.own.extension" namespace for the class
my.own.extension.ExtensionImpl.

Only way I have seen to use extensions is having a xalan prefix to
http://xml.apache.org/xalan/java namespace, and use
xalan:full.qualified.className.method to access the extension function, or
declare a component for the extension element.

I hope I'm wrong and I haven't just seen the way of doing that. And I need
the http:// on the namespace.

Any clues?

-- 

Obrigado,
Fausto.

Re: Java extensions namespaces

Posted by Fausto <ch...@gmail.com>.
Cool. Thank you very much.

On Fri, Oct 24, 2008 at 11:07 AM, Christine Li <jy...@ca.ibm.com> wrote:

>
> No, both Xalan interpretive and compiled processors don't have this
> optimization.
>
> Christine Li
> XML Transformation
> IBM Toronto Lab
> Tel: (905)413-2601
> Email: jycli@ca.ibm.com
>
>
>  *Michael Ludwig <ml...@as-guides.com>*
>
> 24/10/2008 11:34 AM
>   To
> xalan-j-users@xml.apache.org
>  cc
>   Subject
> Re: Java extensions namespaces
>
>
>
>
> Fausto schrieb:
> > Also, I have read in an
> > article<http://www.ibm.com/developerworks/library/x-xalanextensions.html
> >that
> > XSLT processors should have some optimization on extension functions,
> > assuming these functions should not have any side effect and always
> return
> > the same value when some parameter is passed. This assumed, the
> optimization
> > would cache the results of last calls and their parameters, and our
> > functions wouldn't be called as many times we thought them would be
> called.
> >
> > My questions are: does xalan have this optimization [...] ?
>
> Apparently not:
>
> 17:30:31,43 C:\MILU\dev\XSL-Xalan
> # more increment-via-extension.xsl /T1
> <xsl:stylesheet
>     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>     version="1.0"
>     xmlns:own="http://my.own.extension"
>     exclude-result-prefixes="own">
>   <xsl:output omit-xml-declaration="yes" indent="yes"/>
>   <xsl:template match="/*">
>   <xsl:copy>
>    <eins><xsl:value-of select="own:Increment.new()"/></eins>
>    <zwei><xsl:value-of select="own:Increment.new()"/></zwei>
>   </xsl:copy>
>   </xsl:template>
> </xsl:stylesheet>
>
> 17:30:49,20 C:\MILU\dev\XSL-Xalan
> # more urmel.xml
> <Urmel/>
>
> 17:31:00,65 C:\MILU\dev\XSL-Xalan
> # more my\own\extension\Increment.java
> package my.own.extension;
>
> public class Increment {
>     private static int counter;
>     public Increment() {
>         counter++;
>     }
>     public String toString() {
>         return Integer.toString( counter);
>     }
> }
>
> Michael Ludwig
>
>


-- 

Obrigado,
Fausto.

Re: Java extensions namespaces

Posted by Michael Ludwig <ml...@as-guides.com>.
Michael Ludwig schrieb:
> Fausto schrieb:
>>
>> My questions are: does xalan have this optimization [...] ?
> 
> Apparently not:

Forgot to include the result in my previous post:

# xalan urmel.xml increment-via-extension.xsl
<Urmel>
<eins>1</eins>
<zwei>2</zwei>
</Urmel>

So the extension function is called twice. Given the method name is
"new()", everything else would be a little counter-intuitive.

Michael Ludwig

Re: Java extensions namespaces

Posted by Christine Li <jy...@ca.ibm.com>.
No, both Xalan interpretive and compiled processors don't have this 
optimization. 

Christine Li
XML Transformation
IBM Toronto Lab
Tel: (905)413-2601
Email: jycli@ca.ibm.com



Michael Ludwig <ml...@as-guides.com> 
24/10/2008 11:34 AM

To
xalan-j-users@xml.apache.org
cc

Subject
Re: Java extensions namespaces






Fausto schrieb:
> Also, I have read in an
> article<http://www.ibm.com/developerworks/library/x-xalanextensions.html
>that
> XSLT processors should have some optimization on extension functions,
> assuming these functions should not have any side effect and always 
return
> the same value when some parameter is passed. This assumed, the 
optimization
> would cache the results of last calls and their parameters, and our
> functions wouldn't be called as many times we thought them would be 
called.
>
> My questions are: does xalan have this optimization [...] ?

Apparently not:

17:30:31,43 C:\MILU\dev\XSL-Xalan
# more increment-via-extension.xsl /T1
<xsl:stylesheet
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0"
     xmlns:own="http://my.own.extension"
     exclude-result-prefixes="own">
   <xsl:output omit-xml-declaration="yes" indent="yes"/>
   <xsl:template match="/*">
   <xsl:copy>
    <eins><xsl:value-of select="own:Increment.new()"/></eins>
    <zwei><xsl:value-of select="own:Increment.new()"/></zwei>
   </xsl:copy>
   </xsl:template>
</xsl:stylesheet>

17:30:49,20 C:\MILU\dev\XSL-Xalan
# more urmel.xml
<Urmel/>

17:31:00,65 C:\MILU\dev\XSL-Xalan
# more my\own\extension\Increment.java
package my.own.extension;

public class Increment {
     private static int counter;
     public Increment() {
         counter++;
     }
     public String toString() {
         return Integer.toString( counter);
     }
}

Michael Ludwig


Re: Java extensions namespaces

Posted by Michael Ludwig <ml...@as-guides.com>.
Fausto schrieb:
> Also, I have read in an
> article<http://www.ibm.com/developerworks/library/x-xalanextensions.html>that
> XSLT processors should have some optimization on extension functions,
> assuming these functions should not have any side effect and always return
> the same value when some parameter is passed. This assumed, the optimization
> would cache the results of last calls and their parameters, and our
> functions wouldn't be called as many times we thought them would be called.
>
> My questions are: does xalan have this optimization [...] ?

Apparently not:

17:30:31,43 C:\MILU\dev\XSL-Xalan
# more increment-via-extension.xsl /T1
<xsl:stylesheet
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0"
     xmlns:own="http://my.own.extension"
     exclude-result-prefixes="own">
   <xsl:output omit-xml-declaration="yes" indent="yes"/>
   <xsl:template match="/*">
   <xsl:copy>
    <eins><xsl:value-of select="own:Increment.new()"/></eins>
    <zwei><xsl:value-of select="own:Increment.new()"/></zwei>
   </xsl:copy>
   </xsl:template>
</xsl:stylesheet>

17:30:49,20 C:\MILU\dev\XSL-Xalan
# more urmel.xml
<Urmel/>

17:31:00,65 C:\MILU\dev\XSL-Xalan
# more my\own\extension\Increment.java
package my.own.extension;

public class Increment {
     private static int counter;
     public Increment() {
         counter++;
     }
     public String toString() {
         return Integer.toString( counter);
     }
}

Michael Ludwig

Re: Java extensions namespaces

Posted by Fausto <ch...@gmail.com>.
Awesome... meaning xalan ignores the http:// part and works only with the
my.own.extension to find the package, right?

Also, I have read in an
article<http://www.ibm.com/developerworks/library/x-xalanextensions.html>that
XSLT processors should have some optimization on extension functions,
assuming these functions should not have any side effect and always return
the same value when some parameter is passed. This assumed, the optimization
would cache the results of last calls and their parameters, and our
functions wouldn't be called as many times we thought them would be called.

My questions are: does xalan have this optimization, and, if so, is there
any way to "deactivate" it?

Thank you very much,
Fausto.

On Fri, Oct 24, 2008 at 9:20 AM, Christine Li <jy...@ca.ibm.com> wrote:

>
> Hi, Fausto
>
> You can use your own namespace for extension functions. For example, the
> following stylesheet should work if you have the
> my.own.extension.ExtensionImpl in the correct classpath.
> <xsl:stylesheet
>     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>     version="1.0"
>     xmlns:own="*http://my.own.extension* <http://my.own.extension/>"
>     exclude-result-prefixes="own">
>   <xsl:template match="/">
>        <xsl:value-of select="own:ExtensionImpl.new()"/></p>
>   </xsl:template>
> </xsl:stylesheet>
>
> Christine Li
> XML Transformation
> IBM Toronto Lab
> Tel: (905)413-2601
> Email: jycli@ca.ibm.com
>
>
>  *Fausto <ch...@gmail.com>*
>
> 24/10/2008 08:35 AM
>   To
> xalan-j-users@xml.apache.org  cc
>   Subject
> Java extensions namespaces
>
>
>
>
> Hi all,
>
> I am not sure I did understand well how the extension namespaces works on
> xalan-j, because I have not found a way to define my own namespace for the
> extentions.
>
> Like having "*http://my.own.extension* <http://my.own.extension/>"
> namespace for the class my.own.extension.ExtensionImpl.
>
> Only way I have seen to use extensions is having a xalan prefix to *
> http://xml.apache.org/xalan/java* <http://xml.apache.org/xalan/java>namespace, and use xalan:full.qualified.className.method to access the
> extension function, or declare a component for the extension element.
>
> I hope I'm wrong and I haven't just seen the way of doing that. And I need
> the http:// on the namespace.
>
> Any clues?
>
> --
>
> Obrigado,
> Fausto.
>



-- 

Obrigado,
Fausto.

Re: Java extensions namespaces

Posted by Christine Li <jy...@ca.ibm.com>.
Hi, Fausto

You can use your own namespace for extension functions. For example, the 
following stylesheet should work if you have the 
my.own.extension.ExtensionImpl in the correct classpath.
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0" 
    xmlns:own="http://my.own.extension"
    exclude-result-prefixes="own">
  <xsl:template match="/"> 
       <xsl:value-of select="own:ExtensionImpl.new()"/></p>
  </xsl:template>
</xsl:stylesheet>

Christine Li
XML Transformation
IBM Toronto Lab
Tel: (905)413-2601
Email: jycli@ca.ibm.com



Fausto <ch...@gmail.com> 
24/10/2008 08:35 AM

To
xalan-j-users@xml.apache.org
cc

Subject
Java extensions namespaces






Hi all,

I am not sure I did understand well how the extension namespaces works on 
xalan-j, because I have not found a way to define my own namespace for the 
extentions.

Like having "http://my.own.extension" namespace for the class 
my.own.extension.ExtensionImpl.

Only way I have seen to use extensions is having a xalan prefix to 
http://xml.apache.org/xalan/java namespace, and use 
xalan:full.qualified.className.method to access the extension function, or 
declare a component for the extension element.

I hope I'm wrong and I haven't just seen the way of doing that. And I need 
the http:// on the namespace.

Any clues?

-- 

Obrigado,
Fausto.