[EMAIL PROTECTED] wrote:
Hello,

I'm currently working on an extension class for use in an XSL file.

The transformation I want to perform is the following:

Input fragment:
<floatlist>0 1 2 3 4 5 6 7 8</floatlist>

Output fragment:
<vec3 value="0 1 2"/>
<vec3 value="3 4 5"/>
<vec3 value="6 7 8"/>

As to my knowledge there is no way to get this working in XSLT directly (and because for the project behind it there is some more processing required than shown above anyway), I wrote an extension function to do this, and invoke it with this XSL fragment:

<xsl:for-each select="floatlist">
   <xsl:value-of value="ext:makevec3s(.)"/>
</xsl:for-each>


First, you need to understand what xsl:value-of does:

http://www.w3.org/TR/xslt#value-of

"The xsl:value-of element is instantiated to create a text node in the result tree. The required select attribute is an expression; this expression is evaluated and the resulting object is converted to a string as if by a call to the string function."

Next, the string function:

http://www.w3.org/TR/xpath#section-String-Functions

"A node-set is converted to a string by returning the string-value of the node in the node-set that is first in document order. If the node-set is empty, an empty string is returned."

Next, the string-value of a root node:

http://www.w3.org/TR/xpath#root-node

"The string-value of the root node is the concatenation of the string-values of all text node descendants of the root node in document order."

Since your extension function doesn't create any text nodes, the string-value of the document fragment is an empty string.

However, looking at your expected output, you probably want to use xsl:copy-of, since you want to copy the structure of the document fragment to the result tree.

...

     public DocumentFragment makevec3s(String in){
       DocumentFragment dfrag = doc.createDocumentFragment();
             // test float array, no need to show parsing code here
       float[] floats = {0, 1, 2, 3, 4, 5, 6, 7, 8};
             for(int i=2; i<floats.length; i+=3){
           Element v3Element = doc.createElement("vec3");

You should be creating a namespace-aware DOM, by using createElementNS() and setAttributeNS().

Dave

Reply via email to