Assing object to variable

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Assing object to variable

sanne
Hi all,

I'm trying to assign an object to a xsl variable so I can later call a function on it. In Xalan this seems to work out, but in Saxon I can't figure out houw this should be done. It this possible at all? Basically my sheet goes like:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"        xmlns:postcodeStatusObject="anwb.isb.servicefunction.webservice.adresmutatie.PostcodeStatusObject"
 version="1.0" >
... <xsl:variable name="postcode"><xsl:value-of select="postcodeStatusObject:new(/AdresMutatie_1/NieuwAdres/postcode/text(),/AdresMutatie_1/NieuwAdres/huisnummer/text())"/></xsl:variable>
        <xsl:template match="AdresMutatie_1">
                <xsl:element name="bericht">
                ...
<xsl:element name="straat"><xsl:value-of select="postcodeStatusObject:getStraatNaam($postcode)"/></xsl:element>

... </xsl:element>
        </xsl:template>
</xsl:stylesheet>

Where getStraatNaam() is defined on anwb.isb.servicefunction.webservice.adresmutatie.PostcodeStatusObject. The error I get is:

  First argument is not an object instance

I've tried the docs and the web.

Krgrds,

Sanne


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Assing object to variable

Michael Kay
 
This construct:

<xsl:variable name="v">
  <xsl:value-of select="EXP"/>
</xsl:variable>

always produces a result tree fragment consisting of a document node owning
a text node, where the contents of the text node are the result of
converting the value of EXP to a string. If this does something different in
Xalan, I'm very surprised.

If you want the variable v to be the value of expression EXP, you should
write:

<xsl:variable name="v" select="EXP"/>

This habit of writing xsl:value-of inside xsl:variable is very pervasive,
and it's really important to avoid it, except in the rare cases where you
actually do want to construct a new temporary document.

The error message arises because the value you are supplying to
getStraatNam() is a document node.

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


> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> Sanne de Roever
> Sent: 30 September 2005 12:42
> To: [hidden email]
> Subject: [saxon] Assing object to variable
>
> Hi all,
>
> I'm trying to assign an object to a xsl variable so I can
> later call a function on it. In Xalan this seems to work out,
> but in Saxon I can't figure out houw this should be done. It
> this possible at all? Basically my sheet goes like:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"        
xmlns:postcodeStatusObject="anwb.isb.servicefunction.webservice.adresmutatie
.PostcodeStatusObject"

>  version="1.0" >
> ... <xsl:variable name="postcode"><xsl:value-of
> select="postcodeStatusObject:new(/AdresMutatie_1/NieuwAdres/po
> stcode/text(),/AdresMutatie_1/NieuwAdres/huisnummer/text())"/>
> </xsl:variable>
> <xsl:template match="AdresMutatie_1">
> <xsl:element name="bericht">
>        ...
> <xsl:element name="straat"><xsl:value-of
> select="postcodeStatusObject:getStraatNaam($postcode)"/></xsl:element>
>
> ... </xsl:element>
> </xsl:template>
> </xsl:stylesheet>
>
> Where getStraatNaam() is defined on
> anwb.isb.servicefunction.webservice.adresmutatie.PostcodeStatu
> sObject. The error I get is:
>
>   First argument is not an object instance
>
> I've tried the docs and the web.
>
> Krgrds,
>
> Sanne
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Power Architecture Resource Center: Free content, downloads,
> discussions,
> and more. http://solutions.newsforge.com/ibmarch.tmpl
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Serializing value of NodeSet of Extenstion Element

Brett Knights
Hello,

I have an extension element that extends XSLGeneralVariable. (Its
actually a rewrite of the SQLColumn class).

When processing I get the value and can successfully process strings,
numbers, booleans etc.

             final Value v = getSelectValue(context);
...
             stmt.setString(paramIndex, v.asString());
or
            stmt.setInt(paramIndex, (int)v.asNumber());

My problem arises because some of the strings I need to handle contain
markup. e.g.
  the xml

<targetItemDesc>This is some sample text.
<br/>
It has some markup.
</targetItemDesc>


the xslt

<sql:column name="detailedDescription"   type="VARCHAR"
select="targetItemDesc"/>

currently the above would end up being processed by
stmt.setString(paramIndex, v.asString());
and the value that would end up int the db would be
"This is some sample text.

It has some markup."

ideally what I'd like in the db would be:
"This is some sample text.
<br/>
It has some markup."

I am using Saxon 6.5.3.
Any pointers on how to do this would be appreciated.
I assume I need to serialize the Value into a Writer or OutputStream.

TIA
Brett Knights



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Serializing value of NodeSet of Extenstion Element

Michael Kay
> I have an extension element that extends XSLGeneralVariable. (Its
> actually a rewrite of the SQLColumn class).
>
> When processing I get the value and can successfully process strings,
> numbers, booleans etc.
>
>              final Value v = getSelectValue(context);
> ...
>              stmt.setString(paramIndex, v.asString());
> or
>    stmt.setInt(paramIndex, (int)v.asNumber());
>
> My problem arises because some of the strings I need to
> handle contain
> markup. e.g.
>   the xml
>
> <targetItemDesc>This is some sample text.
> <br/>
> It has some markup.
> </targetItemDesc>

You mean the original XML source contained markup. So presumably
getSelectValue() returns an element node that has children? And rather than
just doing v.asString(), which gives the string value of the element node,
you want to serialize the element node as XML?

I forget all the details of how to do this in 6.5.3, but I would think you
need to set up an XMLEmitter with a StringWriter as the destination writer,
and then do a tree walk over the subtree rooted at the element node sending
the events to the XMLEmitter. The copy() method on NodeInfo essentially does
this for you: though it writes to an Outputter rather than directly an
Emitter, so you have to create a GeneralOutputter first, and pipe stuff
through the GeneralOutputter to the Emitter.

Hope this points you in the right direction.

Michael Kay

>
>
> the xslt
>
> <sql:column name="detailedDescription"   type="VARCHAR"
> select="targetItemDesc"/>
>
> currently the above would end up being processed by
> stmt.setString(paramIndex, v.asString());
> and the value that would end up int the db would be
> "This is some sample text.
>
> It has some markup."
>
> ideally what I'd like in the db would be:
> "This is some sample text.
> <br/>
> It has some markup."
>
> I am using Saxon 6.5.3.
> Any pointers on how to do this would be appreciated.
> I assume I need to serialize the Value into a Writer or OutputStream.
>
> TIA
> Brett Knights
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Power Architecture Resource Center: Free content, downloads,
> discussions,
> and more. http://solutions.newsforge.com/ibmarch.tmpl
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help