You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Baq Haidri <bh...@inktomi.com> on 2000/10/27 01:51:45 UTC

Question on extensions

Hi,

(I'm not sure if I need to subscribe to this list first; it didn't say
so anywhere on the site, so I'm just going to crash the party)

I think the extension capability that Xalan offers is great!  However I
have a question.

I want my transformation upon seeing an element in the input file,
generate an element with an attribute in the output file.  This
attribute's value will be a random unique number generated by a java
function.  However, I can't seem to get the syntax right for embedding
an extension function call within an attribute.  I keep getting errors. 
Finally, I just tried creating a separate variable to embed in the value
of my attribute but that doesn't work either.

Here is what I have right now inside my stylesheet:

    <!-- All transformations which occur to a LISTING -->
    <xsl:template match="LISTING">
        <xsl:variable name="documentCode" 
	   
select="java:com.inktomi.rockslide.xdb.DocumentCode.getUniqueCode()" />
        

        <!-- Unique document code returned by a static Java method call
-->
        <DOC url="$documentCode"> </DOC>

    </xsl:template> 


However, I just get this as output:

	<DOC url="$documentCode"/> 

I don't even get a closing </DOC> tag.

What am I doing wrong?

Thanks!
Baq

Re: Question on extensions

Posted by Gary L Peskin <ga...@firstech.com>.
Baq Haidri wrote:
> Here is what I have right now inside my stylesheet:
> 
>     <!-- All transformations which occur to a LISTING -->
>     <xsl:template match="LISTING">
>         <xsl:variable name="documentCode"
> select="java:com.inktomi.rockslide.xdb.DocumentCode.getUniqueCode()" />
>         <!-- Unique document code returned by a static Java method call
> -->
>         <DOC url="$documentCode"> </DOC>
>     </xsl:template>
> 
> However, I just get this as output:
> 
>         <DOC url="$documentCode"/>
> 
> I don't even get a closing </DOC> tag.
> 
> What am I doing wrong?

Well, you are getting a closing DOC tag because, if you look at the
output, you'll see the / just before the > on the DOC tag.  This is
called an empty element and is the equivalent of <DOC...></DOC>.  XSLT
operates on XSLT trees which contain nodes.  On output, these nodes are
written ("serialized") back to your output.  The XML serializer just
sees and empty node so it writes <DOC .../> rather than <DOC ...></DOC>.

Next, the DOC element is called a literal result element and will be
output literally.  To force the value of your variable, use

	<DOC url="{$documentCode}"/>

This is called an Attribute Value Template and the braces will cause
your variable to be evaluated.

Gary