Tags in the value of an XSLT variable?

View: New views
16 Messages — Rating Filter:   Alert me  

Tags in the value of an XSLT variable?

by andyjc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All,

It's quite possible that this is more XSLT-related than Cocoon itself,
but wasn't sure where else to post.

I'm using an XSL transformer and need to capture a tree fragment in the
value of variable ... including the tags themselves.  The reason for
this is because I need to pass the XML excerpt (as a string) to a Java
class which is specifically written to parse it.

I'm trying the following, but this only seems to include the values, and
not the tags:

    <xsl:variable name="gml">
      <xsl:copy-of select="."/>
    </xsl:variable>

Can anyone help?  Is there a trick for this?

Many thanks,

Andy

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Tags in the value of an XSLT variable?

by Betty Harvey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Try this for your xsl:copy:

<xsl:copy><xsl:apply-templates select="@* | node()" /></xsl:copy>

<quote who="Andrew Chamberlain">

> Hi All,
>
> It's quite possible that this is more XSLT-related than Cocoon itself,
> but wasn't sure where else to post.
>
> I'm using an XSL transformer and need to capture a tree fragment in the
> value of variable ... including the tags themselves.  The reason for
> this is because I need to pass the XML excerpt (as a string) to a Java
> class which is specifically written to parse it.
>
> I'm trying the following, but this only seems to include the values, and
> not the tags:
>
>     <xsl:variable name="gml">
>       <xsl:copy-of select="."/>
>     </xsl:variable>
>
> Can anyone help?  Is there a trick for this?
>
> Many thanks,
>
> Andy
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>


/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Betty Harvey                         | Phone: 410-787-9200 FAX: 9830
Electronic Commerce Connection, Inc. |
harvey@...                    | Washington,DC SGML/XML Users Grp
URL:  http://www.eccnet.com          | http://www.eccnet.com/xmlug/
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\/\/
Help Mac fight MLD (http://www.macsteam.org)
Mark your calendar for October 28th (http://www.macsteam.org/BullROast.aspx)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Tags in the value of an XSLT variable?

by dhohls :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

And that is not a "trick", but standard XSLT; see:
http://www.dpawson.co.uk/xsl/sect2/N1930.html#d3389e91 
as select="." only selects the value (string) inside the tag/s.

>>> On 2008/06/27 at 06:48, in message <2415.207.168.47.25.1214585293.squirrel@...>, "Betty Harvey" <harvey@...> wrote:
Try this for your xsl:copy:

<xsl:copy><xsl:apply-templates select="@* | node()" /></xsl:copy>

<quote who="Andrew Chamberlain">

> Hi All,
>
> It's quite possible that this is more XSLT-related than Cocoon itself,
> but wasn't sure where else to post.
>
> I'm using an XSL transformer and need to capture a tree fragment in the
> value of variable ... including the tags themselves.  The reason for
> this is because I need to pass the XML excerpt (as a string) to a Java
> class which is specifically written to parse it.
>
> I'm trying the following, but this only seems to include the values, and
> not the tags:
>
>     <xsl:variable name="gml">
>       <xsl:copy-of select="."/>
>     </xsl:variable>
>
> Can anyone help?  Is there a trick for this?
>
> Many thanks,
>
> Andy



--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard.
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean.  MailScanner thanks Transtec Computers for their support.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Tags in the value of an XSLT variable?

by andyjc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Betty/Derek,

Thanks for getting back.

Yes, that's certainly helped.  I'm now confident that my variable also contains the tags in addition to the values.  It was by changing the "." for "@* | node()" that did it.

So my xslt looks like this:
    <xsl:variable name="gml">
      <xsl:copy-of select="@* | node()"/>
    </xsl:variable>
However, I now believe this variable is still a Node-Tree, and not a String.  I need it to be the latter so I can pass the XML excerpt to the Java method I mentioned earlier (using xalan to do so).

Is there a way of casting/translating a node tree into a String?

Best regards,

Andy



Derek Hohls wrote:
And that is not a "trick", but standard XSLT; see:
http://www.dpawson.co.uk/xsl/sect2/N1930.html#d3389e91
as select="." only selects the value (string) inside the tag/s.

  
On 2008/06/27 at 06:48, in message 2415.207.168.47.25.1214585293.squirrel@..., "Betty Harvey" harvey@... wrote:
        
Try this for your xsl:copy:

<xsl:copy><xsl:apply-templates select="@* | node()" /></xsl:copy>

<quote who="Andrew Chamberlain">
  
Hi All,

It's quite possible that this is more XSLT-related than Cocoon itself,
but wasn't sure where else to post.

I'm using an XSL transformer and need to capture a tree fragment in the
value of variable ... including the tags themselves.  The reason for
this is because I need to pass the XML excerpt (as a string) to a Java
class which is specifically written to parse it.

I'm trying the following, but this only seems to include the values, and
not the tags:

    <xsl:variable name="gml">
      <xsl:copy-of select="."/>
    </xsl:variable>

Can anyone help?  Is there a trick for this?

Many thanks,

Andy
    



--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard.
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean.  MailScanner thanks Transtec Computers for their support.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...

.

  
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@...

Re: Tags in the value of an XSLT variable?

by dhohls :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Andy

This is confusing.  In your original post, you said you wanted to:
"capture a tree fragment in the value of variable ... including the tags themselves"
This is now what you have.

I am also not sure how you differentiate between a Node Tree vs a String.
At the end, XML is just plain text.  The fact that it has pointy brackets in it
is because we assume that the processing software will be able to make use
of it.  So I think the answer lies in the Java code you have written - if it treats
the incoming variable as just having plain text, then the brackets should make
no difference.  Maybe you need to expand more on what you want to happen
on the Java side.... (tho' that is probably outside my scope of expertise)

Derek

>>> On 2008/06/30 at 01:15, in message <4868C04B.8010507@...>, Andrew Chamberlain <andyc@...> wrote:
Hi Betty/Derek,

Thanks for getting back.

Yes, that's certainly helped.  I'm now confident that my variable also contains the tags in addition to the values.  It was by changing the "." for "@* | node()" that did it.

So my xslt looks like this:
<xsl:variable name="gml">      <xsl:copy-of select="@* | node()"/>    </xsl:variable>
However, I now believe this variable is still a Node-Tree, and not a String.
 I need it to be the latter so I can pass the XML excerpt to the Java method
 I mentioned earlier (using xalan to do so).

Is there a way of casting/translating a node tree into a String?

Best regards,

Andy


Derek Hohls wrote:

And that is not a "trick", but standard XSLT; see:http://www.dpawson.co.uk/xsl/sect2/N1930.html#d3389e91as select="." only selects the value (string) inside the tag/s.


On 2008/06/27 at 06:48, in message <2415.207.168.47.25.1214585293.squirrel@...> ( mailto:2415.207.168.47.25.1214585293.squirrel@... ), "Betty Harvey" <harvey@...> ( mailto:harvey@... ) wrote:
        Try this for your xsl:copy:
<xsl:copy><xsl:apply-templates select="@* | node()" /></xsl:copy><quote who="Andrew Chamberlain">  

Hi All,

It's quite possible that this is more XSLT-related than Cocoon itself,
but wasn't sure where else to post.

I'm using an XSL transformer and need to capture a tree fragment in the
value of variable ... including the tags themselves.  The reason for
this is because I need to pass the XML excerpt (as a string) to a Java
class which is specifically written to parse it.

I'm trying the following, but this only seems to include the values, and
not the tags:

    <xsl:variable name="gml">      <xsl:copy-of select="."/>    </xsl:variable>
Can anyone help?  Is there a trick for this?

Many thanks,

Andy



--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard.
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean.  MailScanner thanks Transtec Computers for their support.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Tags in the value of an XSLT variable?

by Andreas Hartmann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Andrew Chamberlain schrieb:

> Hi Betty/Derek,
>
> Thanks for getting back.
>
> Yes, that's certainly helped.  I'm now confident that my variable also
> contains the tags in addition to the values.  It was by changing the "."
> for "@* | node()" that did it.
>
> So my xslt looks like this:
>
>     <xsl:variable name="gml">
>       <xsl:copy-of select="@* | node()"/>
>     </xsl:variable>
>
> However, I now believe this variable is still a Node-Tree, and not a
> String.  I need it to be the latter so I can pass the XML excerpt to the
> Java method I mentioned earlier (using xalan to do so).
>
> Is there a way of casting/translating a node tree into a String?

That would be XML serializing. AFAIK XSLT is not capable of this (I
don't know about XSLT 2.0, though). Why do you have to convert the
fragment to a string? Wouldn't it be more straightforward to pass the
fragment to the Java code, so that it doesn't have to be parsed again?

-- Andreas


>
> Best regards,
>
> Andy
>
> ------------------------------------------------------------------------
>
> Derek Hohls wrote:
>> And that is not a "trick", but standard XSLT; see:
>> http://www.dpawson.co.uk/xsl/sect2/N1930.html#d3389e91
>> as select="." only selects the value (string) inside the tag/s.
>>
>>  
>>>>> On 2008/06/27 at 06:48, in message <2415.207.168.47.25.1214585293.squirrel@...>, "Betty Harvey" <harvey@...> wrote:
>>>>>        
>> Try this for your xsl:copy:
>>
>> <xsl:copy><xsl:apply-templates select="@* | node()" /></xsl:copy>
>>
>> <quote who="Andrew Chamberlain">
>>  
>>> Hi All,
>>>
>>> It's quite possible that this is more XSLT-related than Cocoon itself,
>>> but wasn't sure where else to post.
>>>
>>> I'm using an XSL transformer and need to capture a tree fragment in the
>>> value of variable ... including the tags themselves.  The reason for
>>> this is because I need to pass the XML excerpt (as a string) to a Java
>>> class which is specifically written to parse it.
>>>
>>> I'm trying the following, but this only seems to include the values, and
>>> not the tags:
>>>
>>>     <xsl:variable name="gml">
>>>       <xsl:copy-of select="."/>
>>>     </xsl:variable>
>>>
>>> Can anyone help?  Is there a trick for this?
>>>
>>> Many thanks,
>>>
>>> Andy
>>>    
>>
>>
>>
>> --
>> This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard.
>> The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.
>>
>> This message has been scanned for viruses and dangerous content by MailScanner,
>> and is believed to be clean.  MailScanner thanks Transtec Computers for their support.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-mail: users-help@...
>>
>> .
>>
>>  


--
Andreas Hartmann, CTO
BeCompany GmbH
http://www.becompany.ch
Tel.: +41 (0) 43 818 57 01


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Tags in the value of an XSLT variable?

by Betty Harvey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Andy:

I am not sure how JAVA handles an XML snippet but if you are passing the
snippet as variable you should be able to cast it as a string.  If
not you could try encapsulating it at CDATA section and the parser
will ignore anything in the CDATA section:

<![CDATA[
<a>My XML</a>
]]>

Betty

<quote who="Andrew Chamberlain">

>         Hi Betty/Derek,
>
>  Thanks for getting back.
>
>  Yes, that's certainly helped.  I'm now confident that my variable also
> contains the tags in addition to the values.  It was by changing the "."
> for "@* | node()" that did it.
>
>  So my xslt looks like this:
>                    However, I now believe this variable is still a
> Node-Tree, and not a String.  I need it to be the
> latter so I can pass the XML excerpt to the Java method
> I mentioned earlier (using xalan to do so).
>
>  Is there a way of casting/translating a node tree into a String?
>
>  Best regards,
>
>  Andy
>
>
>  Derek Hohls wrote:    And that is not a "trick", but standard XSLT; see:
> http://www.dpawson.co.uk/xsl/sect2/N1930.html#d3389e91 as select="." only
> selects the value (string) inside the tag/s.
> On 2008/06/27 at 06:48, in message , "Betty Harvey"  wrote:
>             Try this for your xsl:copy:               Hi All,  It's quite
> possible that this is more XSLT-related than Cocoon itself, but wasn't
> sure where else to post.  I'm using an XSL transformer and need to
> capture a tree fragment in the value of variable ... including the tags
> themselves.  The reason for this is because I need to pass the XML
> excerpt (as a string) to a Java class which is specifically written to
> parse it.  I'm trying the following, but this only seems to include the
> values, and not the tags:                    Can anyone help?  Is there a
> trick for this?  Many thanks,  Andy              -- This message is
> subject to the CSIR's copyright terms and conditions, e-mail legal
> notice, and implemented Open Document Format (ODF) standard. The full
> disclaimer details can be found at http://www.csir.co.za/disclaimer.html.
>  This message has been scanned for viruses and dangerous content by
> MailScanner, and is believed to be clean.  MailScanner thanks Transtec
> Computers for their support.
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: users-unsubscribe@... For additional
> commands, e-mail: users-help@...  .
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: users-unsubscribe@... For additional
> commands, e-mail: users-help@...


/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Betty Harvey                         | Phone: 410-787-9200 FAX: 9830
Electronic Commerce Connection, Inc. |
harvey@...                    | Washington,DC SGML/XML Users Grp
URL:  http://www.eccnet.com          | http://www.eccnet.com/xmlug/
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\/\/
Help Mac fight MLD (http://www.macsteam.org)
Mark your calendar for October 28th (http://www.macsteam.org/BullROast.aspx)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Tags in the value of an XSLT variable?

by andyjc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Andreas,

That's a good tip about passing the fragment as a Node instead of a String.  It didn't occur to me because I mistakenly thought that only primitive-type variables could be passed from Cocoon to Java.

Thanks,

Andy



Andreas Hartmann wrote:
Andrew Chamberlain schrieb:
  
Hi Betty/Derek,

Thanks for getting back.

Yes, that's certainly helped.  I'm now confident that my variable also
contains the tags in addition to the values.  It was by changing the "."
for "@* | node()" that did it.

So my xslt looks like this:

    <xsl:variable name="gml">
      <xsl:copy-of select="@* | node()"/>
    </xsl:variable>

However, I now believe this variable is still a Node-Tree, and not a
String.  I need it to be the latter so I can pass the XML excerpt to the
Java method I mentioned earlier (using xalan to do so).

Is there a way of casting/translating a node tree into a String?
    

That would be XML serializing. AFAIK XSLT is not capable of this (I
don't know about XSLT 2.0, though). Why do you have to convert the
fragment to a string? Wouldn't it be more straightforward to pass the
fragment to the Java code, so that it doesn't have to be parsed again?

-- Andreas


  
Best regards,

Andy

------------------------------------------------------------------------

Derek Hohls wrote:
    
And that is not a "trick", but standard XSLT; see:
http://www.dpawson.co.uk/xsl/sect2/N1930.html#d3389e91
as select="." only selects the value (string) inside the tag/s.


      
On 2008/06/27 at 06:48, in message 2415.207.168.47.25.1214585293.squirrel@..., "Betty Harvey" harvey@... wrote:

            
Try this for your xsl:copy:

<xsl:copy><xsl:apply-templates select="@* | node()" /></xsl:copy>

<quote who="Andrew Chamberlain">

      
Hi All,

It's quite possible that this is more XSLT-related than Cocoon itself,
but wasn't sure where else to post.

I'm using an XSL transformer and need to capture a tree fragment in the
value of variable ... including the tags themselves.  The reason for
this is because I need to pass the XML excerpt (as a string) to a Java
class which is specifically written to parse it.

I'm trying the following, but this only seems to include the values, and
not the tags:

    <xsl:variable name="gml">
      <xsl:copy-of select="."/>
    </xsl:variable>

Can anyone help?  Is there a trick for this?

Many thanks,

Andy

        

--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard.
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean.  MailScanner thanks Transtec Computers for their support.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...

.


      


--
Andreas Hartmann, CTO
BeCompany GmbH
http://www.becompany.ch
Tel.: +41 (0) 43 818 57 01


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...

.

  
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@...

Passing a node-set from XSLT to Java

by andyjc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All,

I'm trying to pass a tree fragment from XSLT to Java in the following
way, and I'm not sure if the node-set is getting through correctly.  The
XML is:

  <gml:Polygon>
   ...
  </gml:Polygon>

and the XSLT is:

  <xsl:stylesheet ... myClass="xalan://my.package.name.MyClass">
    ...
    <xsl:variable name="gmlAdder" select="myClass:new()"/>

    <xsl:variable name="gml">
      <xsl:copy-of select="@* | node()"/>
    </xsl:variable>

    <xsl:variable name="result" select="myClass:addGML($gmlAdder,$gml)"/>
    ...
  </xsl:stylesheet>

where the addGML method is:

  public String addGML(org.w3c.dom.Node myNode)
  {
     ...
     return (myNode.getNodeName());
  }


This gives the 'result' variable the value of "#text", but when I was
expecting "gml:Polygon".

Has anyone else managed to transfer a node-set to Java?  If so, did you
use xalan?

Any tips would be greatly appreciated.

Thanks,

Andy

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Passing a node-set from XSLT to Java

by Luca Morandini-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Andrew Chamberlain wrote:
> Hi All,
>
> I'm trying to pass a tree fragment from XSLT to Java in the following
> way, and I'm not sure if the node-set is getting through correctly.  The
> XML is:
...
>
> This gives the 'result' variable the value of "#text", but when I was
> expecting "gml:Polygon".

Not all XML fragments are nodesets in XSLT 1.0 (XSLT 2.0 is way better
in this respect), hence you could try using the node extension of Xalan.

I haven't tried passing nodeset() to Java, but I presume this example
may help you:

Pass this expression: xalan:nodeset($y-vector)

Where y-vector comes from an ordinary XML fragment like this:
   <xsl:template name="get-y-vector">
     <xsl:param name="geom"/>
     <vector>
       <xsl:for-each select="str:tokenize($geom, ' ')">
       <xsl:if test="string-length(substring-before(., ','))!=0">
         <y><xsl:value-of select="substring-before(., ',')"/></y>
         </xsl:if>
       </xsl:for-each>
     </vector>
   </xsl:template>

Regards,

--------------------
    Luca Morandini
www.lucamorandini.it
--------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Passing a node-set from XSLT to Java

by andyjc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Luca,

That was it!  I changed the line which did the insert to:
<xsl:variable name="result" select="myClass:addGML($gmlAdder,xalan:nodeset($gml)/gml:Polygon)"/>
Many thanks for your help!

Andy



Luca Morandini wrote:
Andrew Chamberlain wrote:
  
Hi All,

I'm trying to pass a tree fragment from XSLT to Java in the following
way, and I'm not sure if the node-set is getting through correctly.  The
XML is:
    
...
  
This gives the 'result' variable the value of "#text", but when I was
expecting "gml:Polygon".
    

Not all XML fragments are nodesets in XSLT 1.0 (XSLT 2.0 is way better
in this respect), hence you could try using the node extension of Xalan.

I haven't tried passing nodeset() to Java, but I presume this example
may help you:

Pass this expression: xalan:nodeset($y-vector)

Where y-vector comes from an ordinary XML fragment like this:
   <xsl:template name="get-y-vector">
     <xsl:param name="geom"/>
     <vector>
       <xsl:for-each select="str:tokenize($geom, ' ')">
       <xsl:if test="string-length(substring-before(., ','))!=0">
         <y><xsl:value-of select="substring-before(., ',')"/></y>
         </xsl:if>
       </xsl:for-each>
     </vector>
   </xsl:template>

Regards,

--------------------
    Luca Morandini
www.lucamorandini.it
--------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


  
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@...

Re: Passing a node-set from XSLT to Java

by andyjc :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Luca/All,

Sorry.  On further testing, we're still not getting through the full
tree fragment to Java.

I've adapted the java method to give details of what it receives:

  public String addGML(org.w3c.dom.Node myNode)
  {
       System.out.println("Class = "+node.getClass().getName());
       System.out.println("Name = "+node.getNodeName());
       System.out.println("Has children = "+(node.hasChildNodes()?"Yes":"No"));
       System.out.println("First Child Name = "+node.getFirstChild().getNodeName());
       System.out.println("First Child Text = "+node.getFirstChild().getTextContent());
  }

and from this comes the following output:

  Class = org.apache.xml.dtm.ref.DTMNodeProxy
  Name = gml:Polygon
  Has children = Yes
  First Child Name = #text

The last line (which uses the getTextContent() method) throws the
following exception:

javax.xml.transform.TransformerException: java.lang.AbstractMethodError:
org.apache.xml.dtm.ref.DTMNodeProxy.getTextContent()Ljava/lang/String;
        at
org.apache.xalan.extensions.ExtensionHandlerJavaClass.callFunction(ExtensionHandlerJavaClass.java:396)
        ...

Firstly, I was expecting the Class to be "org.w3c.dom.Node", so does
anyone know how I can enable this?  I was also expecting the name of the
first child to be "gml:exterior" instead of a "#text".  The XML I'm
sending is given below:

    <gml:Polygon gml:id="GATS1153_10">
      <gml:exterior>
        <gml:LinearRing>
          <gml:posList srsDimension="2">-155.42 55.58</gml:posList>
        </gml:LinearRing>
      </gml:exterior>
    </gml:Polygon>

Is it possible I actually need to pass a tree fragment, rather than a
node-set?

As a reminder, the XSLT given below.  Any help would me greatly
appreciated.  In simple terms, I'm just trying to pass the above XML
from XSLT to Java, preferably as a w3c Node.

Kind regards,

Andy

The XSLT:

  <xsl:stylesheet ... myClass="xalan://my.package.name.MyClass">
    ...
    <xsl:variable name="gmlAdder" select="myClass:new()"/>

    <xsl:variable name="gml">
      <xsl:copy-of select="@* | node()"/>
    </xsl:variable>

    <xsl:variable name="result" select="myClass:addGML($gmlAdder,$gml)"/>
    ...
  </xsl:stylesheet>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Passing a node-set from XSLT to Java

by Jason Johnston-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Andrew Chamberlain wrote:

> Hi Luca/All,
>
> Sorry.  On further testing, we're still not getting through the full
> tree fragment to Java.
>
> I've adapted the java method to give details of what it receives:
>
>  public String addGML(org.w3c.dom.Node myNode)
>  {
>       System.out.println("Class = "+node.getClass().getName());
>       System.out.println("Name = "+node.getNodeName());
>       System.out.println("Has children =
> "+(node.hasChildNodes()?"Yes":"No"));
>       System.out.println("First Child Name =
> "+node.getFirstChild().getNodeName());
>       System.out.println("First Child Text =
> "+node.getFirstChild().getTextContent());
>  }
>
> and from this comes the following output:
>
>  Class = org.apache.xml.dtm.ref.DTMNodeProxy
>  Name = gml:Polygon
>  Has children = Yes
>  First Child Name = #text
>
> The last line (which uses the getTextContent() method) throws the
> following exception:
>
> javax.xml.transform.TransformerException: java.lang.AbstractMethodError:
> org.apache.xml.dtm.ref.DTMNodeProxy.getTextContent()Ljava/lang/String;
>        at
> org.apache.xalan.extensions.ExtensionHandlerJavaClass.callFunction(ExtensionHandlerJavaClass.java:396)
>
>        ...
>
> Firstly, I was expecting the Class to be "org.w3c.dom.Node", so does
> anyone know how I can enable this?

DTMNodeProxy is the concrete implementation class, so it makes sense
that you get that.  org.w3c.dom.Node would just be one of the (possibly
many) interfaces it implements so I wouldn't expect getClass().getName()
to return it.  I think what you're really wanting is node.getNodeType()
which returns one of the node type constants (see the Node javadoc).

> I was also expecting the name of the
> first child to be "gml:exterior" instead of a "#text".  The XML I'm
> sending is given below:
>
>    <gml:Polygon gml:id="GATS1153_10">
>      <gml:exterior>
>        <gml:LinearRing>
>          <gml:posList srsDimension="2">-155.42 55.58</gml:posList>
>        </gml:LinearRing>
>      </gml:exterior>
>    </gml:Polygon>

My guess is that the first child of gml:Polygon is actually the
whitespace text node before the gml:exterior element.  Pretty easy to
test by looking at the length of getChildNodes() which would be 3.  To
get straight to the gml:exterior you could use getElementsByTagNameNS,
or check each child node's nodeType for ELEMENT_NODE.

>
> Is it possible I actually need to pass a tree fragment, rather than a
> node-set?
>
> As a reminder, the XSLT given below.  Any help would me greatly
> appreciated.  In simple terms, I'm just trying to pass the above XML
> from XSLT to Java, preferably as a w3c Node.
>
> Kind regards,
>
> Andy
>
> The XSLT:
>
>  <xsl:stylesheet ... myClass="xalan://my.package.name.MyClass">
>    ...
>    <xsl:variable name="gmlAdder" select="myClass:new()"/>
>
>    <xsl:variable name="gml">
>      <xsl:copy-of select="@* | node()"/>
>    </xsl:variable>
>
>    <xsl:variable name="result" select="myClass:addGML($gmlAdder,$gml)"/>
>    ...
>  </xsl:stylesheet>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Passing a node-set from XSLT to Java

by Luca Morandini-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Andrew Chamberlain wrote:
>
> The last line (which uses the getTextContent() method) throws the
> following exception:
>
> javax.xml.transform.TransformerException: java.lang.AbstractMethodError:
> org.apache.xml.dtm.ref.DTMNodeProxy.getTextContent()Ljava/lang/String;
>        at
> org.apache.xalan.extensions.ExtensionHandlerJavaClass.callFunction(ExtensionHandlerJavaClass.java:396)

For a better understanding, you should look at the portion of the stack
trace following "caused by".


> Firstly, I was expecting the Class to be "org.w3c.dom.Node", so does
> anyone know how I can enable this?  

Rather difficult, since org.w3c.dom.Node is an interface, not a class:
the object that is passed to the addGML function is an instance of
org.apache.xml.dtm.ref.DTMNodeProxy, an actual class which happens to
implement org.w3c.dom.Node.


> I was also expecting the name of the
> first child to be "gml:exterior" instead of a "#text".

Understandable, since your XML has newlines and blanks before
gml:exterior: try stripping all this baggage before parsing.

Regards,

--------------------
    Luca Morandini
www.lucamorandini.it
--------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Passing a node-set from XSLT to Java

by andyjc :: Rate this Message: