Quantcast

Return a sequene of elements from an extension instruction

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Return a sequene of elements from an extension instruction

Patrik.Stellmann

Hi,

 

we have an extension instruction implemented that should return a sequence of elements like this simplified sample (Saxon EE 9.6.0.7 called from oXygen):

 

public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {

      final SequenceOutputter out = context.getController().allocateSequenceOutputter(50);

     

      out.startElement(new NoNamespaceName("test1"), Untyped.getInstance(), locationId, 0);

      out.characters("text1", locationId, 0);

      out.endElement();

     

      out.startElement(new NoNamespaceName("test2"), Untyped.getInstance(), locationId, 0);

      out.characters("text2", locationId, 0);

      out.endElement();

     

      return SequenceTool.toLazySequence(out.iterate());

}

 

But the result does not behave like a normal sequence since I can’t select the 2nd element with $result/self::test2:


<xsl:variable name="result" as="element()*">
    
<my:test/>
</xsl:variable>
<xsl:message>test1: <xsl:value-of select="$result/self::test1"/></xsl:message>
<xsl:message>test2: <xsl:value-of select="$result/self::test2"/></xsl:message>

 

This code produces this output:

 

      test1: 'text1'

test2: ''

 

Is there a better way to create a sequence of elements?

 

BTW: This xslt code works fine:

 

<xsl:variable name="result2">
    
<gui:test select="."/>
</xsl:variable>
<xsl:message>test1: '<xsl:value-of select="$result2/test1"/>'</xsl:message>
<xsl:message>test2: '<xsl:value-of select="$result2/test2"/>'</xsl:message>

 

 

Thanks and regards,

Patrik

 


------------------------------------------------------------------
Systemarchitektur & IT-Projekte
Tel: +49 40 33449-1142
Fax: +49 40 33449-1400
E-Mail: [hidden email]


GDV Dienstleistungs-GmbH & Co. KG
Glockengießerwall 1
D-20095 Hamburg
www.gdv-dl.de

Sitz und Registergericht: Hamburg
HRA 93 894
USt.-IdNr : DE 205183123

Komplementärin:
GDV Beteiligungsgesellschaft mbH
Sitz und Registergericht: Hamburg
HRB 71 153

Geschäftsführer:
Dr. Jens Bartenwerfer
Michael Bathke
Volker Sonnenburg

------------------------------------------------------------------
Diese E-Mail und alle Anhänge enthalten vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe der E-Mail ist nicht gestattet.

This e-mail and any attached files may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Return a sequene of elements from an extension instruction

Michael Kay
Not sure why it shouldn't work, but have you tried replacing

return SequenceTool.toLazySequence(out.iterate());

with

return out.getSequence());

which is a lot simpler internally?

Also, try calling out.startContent() after out.startElement() - that's a required part of the Receiver protocol unless you have something in your pipeline (like a ComplexContentOutputter) that does it for you.

The Receiver API is pretty low-level. A better choice might be to use a StAX XMLStreamWriter. You can get one using s9api DocumentBuilder.getBuildingStreamWriter().


Michael Kay
Saxonica



On 17 Feb 2016, at 06:17, Dr. Patrik Stellmann <[hidden email]> wrote:

Hi,

 

we have an extension instruction implemented that should return a sequence of elements like this simplified sample (Saxon EE 9.6.0.7 called from oXygen):

 

public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {

      final SequenceOutputter out = context.getController().allocateSequenceOutputter(50);

     

      out.startElement(new NoNamespaceName("test1"), Untyped.getInstance(), locationId, 0);

      out.characters("text1", locationId, 0);

      out.endElement();

     

      out.startElement(new NoNamespaceName("test2"), Untyped.getInstance(), locationId, 0);

      out.characters("text2", locationId, 0);

      out.endElement();

     

      return SequenceTool.toLazySequence(out.iterate());

}

 

But the result does not behave like a normal sequence since I can’t select the 2nd element with $result/self::test2:


<xsl:variable name="result" as="element()*">
    
<my:test/>
</xsl:variable>
<xsl:message>test1: <xsl:value-of select="$result/self::test1"/></xsl:message>
<xsl:message>test2: <xsl:value-of select="$result/self::test2"/></xsl:message>

 

This code produces this output:

 

      test1: 'text1'

test2: ''

 

Is there a better way to create a sequence of elements?

 

BTW: This xslt code works fine:

 

<xsl:variable name="result2">
    
<gui:test select="."/>
</xsl:variable>
<xsl:message>test1: '<xsl:value-of select="$result2/test1"/>'</xsl:message>
<xsl:message>test2: '<xsl:value-of select="$result2/test2"/>'</xsl:message>

 

 

Thanks and regards,

Patrik

 


------------------------------------------------------------------
Systemarchitektur & IT-Projekte
Tel: +49 40 33449-1142
Fax: +49 40 33449-1400
E-Mail: [hidden email]



GDV Dienstleistungs-GmbH & Co. KG
Glockengießerwall 1
D-20095 Hamburg
www.gdv-dl.de

Sitz und Registergericht: Hamburg
HRA 93 894
USt.-IdNr : DE 205183123

Komplementärin:
GDV Beteiligungsgesellschaft mbH
Sitz und Registergericht: Hamburg
HRB 71 153

Geschäftsführer:
Dr. Jens Bartenwerfer
Michael Bathke
Volker Sonnenburg

------------------------------------------------------------------
Diese E-Mail und alle Anhänge enthalten vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe der E-Mail ist nicht gestattet.

This e-mail and any attached files may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Return a sequene of elements from an extension instruction

Patrik.Stellmann
In reply to this post by Patrik.Stellmann

Thanks for the hints.

 

Using

 

return out.getSequence());

 

and adding

 

out.startContent();

 

didn’t help.

 

 

However, I changed my code to

 

final Processor         processor   = new Processor(context.getConfiguration());

final DocumentBuilder   builder     = processor.newDocumentBuilder();

 

BuildingStreamWriterImpl writer = builder.newBuildingStreamWriter();

 

writer.writeStartElement("test1");

writer.writeCharacters("text1");

writer.writeEndElement();

 

writer.writeStartElement("test2");

writer.writeCharacters("text2");

writer.writeEndElement();

 

return writer.getDocumentNode().getUnderlyingValue();

 

and this is working fine now – although it returns a document-node instead of a sequence of elements, but that’s OK.

 

Patrik

 

 


------------------------------------------------------------------
Systemarchitektur & IT-Projekte
Tel: +49 40 33449-1142
Fax: +49 40 33449-1400
E-Mail: [hidden email]


Von: Michael Kay [mailto:[hidden email]]
Gesendet: Mittwoch, 17. Februar 2016 08:55
An: Mailing list for the SAXON XSLT and XQuery processor
Betreff: Re: [saxon] Return a sequene of elements from an extension instruction

 

Not sure why it shouldn't work, but have you tried replacing

 

return SequenceTool.toLazySequence(out.iterate());

 

with

 

return out.getSequence());

 

which is a lot simpler internally?

 

Also, try calling out.startContent() after out.startElement() - that's a required part of the Receiver protocol unless you have something in your pipeline (like a ComplexContentOutputter) that does it for you.

 

The Receiver API is pretty low-level. A better choice might be to use a StAX XMLStreamWriter. You can get one using s9api DocumentBuilder.getBuildingStreamWriter().

 

 

Michael Kay

Saxonica

GDV Dienstleistungs-GmbH & Co. KG
Glockengießerwall 1
D-20095 Hamburg
www.gdv-dl.de

Sitz und Registergericht: Hamburg
HRA 93 894
USt.-IdNr : DE 205183123

Komplementärin:
GDV Beteiligungsgesellschaft mbH
Sitz und Registergericht: Hamburg
HRB 71 153

Geschäftsführer:
Dr. Jens Bartenwerfer
Michael Bathke
Volker Sonnenburg

------------------------------------------------------------------
Diese E-Mail und alle Anhänge enthalten vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe der E-Mail ist nicht gestattet.

This e-mail and any attached files may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Loading...