processing content of extension instruction

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

processing content of extension instruction

Patrik.Stellmann
Hi,

I already implemented some extension instructions, for instance gui:message-dialog (working only when called from within oxygen). Now I'd like to allow the text to be specified as the content of this element rather than in the text attribute. Unfortunately, I could not figure out how to process the content nodes. (I used getStringContent() at first, which works for <xsl:text> but of course not for other instructions like <xsl:value-of>). Since I could not find any samples for how to process the content (beside StyleElement) of extension instructions, could you give me some hints how to do this?

Thanks and regards,

Patrik

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:
Volker Sonnenburg
Heiko Beermann

------------------------------------------------------------------
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 distributionof the material in this e-mail is strictly forbidden.


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
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
|

Re: processing content of extension instruction

Michael Kay
Your extension instruction will implement the class ExtensionInstruction, which implements StyleElement, which implements ElementImpl and therefore NodeInfo. It is simply a node on the stylesheet tree. So you can call things like iterateAxis() to find the children, or getStringValue() to get the string value.

Michael Kay
Saxonica


On 11 May 2015, at 10:42, [hidden email] wrote:

Hi,

I already implemented some extension instructions, for instance gui:message-dialog (working only when called from within oxygen). Now I'd like to allow the text to be specified as the content of this element rather than in the text attribute. Unfortunately, I could not figure out how to process the content nodes. (I used getStringContent() at first, which works for <xsl:text> but of course not for other instructions like <xsl:value-of>). Since I could not find any samples for how to process the content (beside StyleElement) of extension instructions, could you give me some hints how to do this?

Thanks and regards,

Patrik

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:
Volker Sonnenburg
Heiko Beermann

------------------------------------------------------------------
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 distributionof the material in this e-mail is strictly forbidden.


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
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
|

Antwort: Re: processing content of extension instruction

Patrik.Stellmann
That's exactly what I did. But getStringValue() returns only the static text content from the xslt code - not the values returned by the instructions at runtime.

For instance using this test code:

        <xsl:variable name="variable" as="xs:string">CorrectContent</xsl:variable>
        <gui:message-dialog>
                <xsl:variable name="unusedVariable">WrongContent</xsl:variable>
                <xsl:text>StaticContent</xsl:text>
                <xsl:value-of select="$variable"/>
        </gui:option-dialog>

I get "WrongContentStaticContent" rather than "StaticContentCorrectContent".


However, I managed to make it work by compiling the child nodes and treating the expressions the same way as the attributes in the samples:

public class GuiMessageDialog extends ExtensionInstruction {

        @Override
        protected void prepareAttributes() throws XPathException {
                // no attributes
        }

        @Override
        public boolean mayContainSequenceConstructor() {
                return true;
        }

        @Override
        public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException {
                AxisIterator childIterator = iterateAxis(AxisInfo.CHILD);

                final List<Expression> childExprList = new LinkedList<Expression>();
                NodeInfo child = childIterator.next();
                while (child != null) {
                        if (child instanceof StyleElement) {
                                final Expression childExpr = ((StyleElement)child).compile(exec, decl);
                                if (childExpr != null) {
                                        childExprList.add(childExpr);
                                }
                        }
                        child = childIterator.next();
                }
                return new MessageDialogInstruction(childExprList);
        }

        private static class MessageDialogInstruction extends SimpleExpression {

                public MessageDialogInstruction(List<Expression> childExprList) {
                        setArguments(childExprList.toArray(new Expression[childExprList.size()]));
                }

                public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
                        String textString = "";
                        for (int i = 0; i < arguments.length; ++i) {
                                SequenceIterator iterator = arguments[i].iterate();
                                Item item = iterator.next();
                                while (item != null) {
                                        textString += item.getStringValue();
                                        item = iterator.next();
                                }
                        }

                        JOptionPane.showMessageDialog(
                                        (Frame)PluginWorkspaceProvider.getPluginWorkspace().getParentFrame(),
                                        textString,
                                        "Message",
                                        JOptionPane.PLAIN_MESSAGE);

                        return EmptySequence.getInstance();
                }

                public int getImplementationMethod() {
                        return Expression.EVALUATE_METHOD;
                }

                public String getExpressionType() {
                        return "gui:message-dialog";
                }
        }

}

Is this the correct way?

Patrik




Von:        Michael Kay <[hidden email]>
An:        Mailing list for the SAXON XSLT and XQuery processor <[hidden email]>,
Datum:        11.05.2015 15:00
Betreff:        Re: [saxon] processing content of extension instruction




Your extension instruction will implement the class ExtensionInstruction, which implements StyleElement, which implements ElementImpl and therefore NodeInfo. It is simply a node on the stylesheet tree. So you can call things like iterateAxis() to find the children, or getStringValue() to get the string value.

Michael Kay
Saxonica


On 11 May 2015, at 10:42, [hidden email] wrote:

Hi,

I already implemented some extension instructions, for instance gui:message-dialog (working only when called from within oxygen). Now I'd like to allow the text to be specified as the content of this element rather than in the text attribute. Unfortunately, I could not figure out how to process the content nodes. (I used getStringContent() at first, which works for <xsl:text> but of course not for other instructions like <xsl:value-of>). Since I could not find any samples for how to process the content (beside StyleElement) of extension instructions, could you give me some hints how to do this?


Thanks and regards,


Patrik

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:
Volker Sonnenburg
Heiko Beermann

------------------------------------------------------------------
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 distributionof the material in this e-mail is strictly forbidden.


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
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
|

Re: Antwort: Re: processing content of extension instruction

Michael Kay

On 12 May 2015, at 06:47, [hidden email] wrote:

That's exactly what I did. But getStringValue() returns only the static text content from the xslt code - not the values returned by the instructions at runtime.

Well, that’s what you said you wanted...

For instance using this test code:

        <xsl:variable name="variable" as="xs:string">CorrectContent</xsl:variable>
        <gui:message-dialog>
                <xsl:variable name="unusedVariable">WrongContent</xsl:variable>
                <xsl:text>StaticContent</xsl:text>
                <xsl:value-of select="$variable"/>
        </gui:option-dialog>

I get "WrongContentStaticContent" rather than "StaticContentCorrectContent".

If the content of your extension instruction is a sequence constructor, then you can compile it into an Expression using the method StyleElement.compileSequenceConstructor().

With the code you have written, I don’t think it will handle variable declarations.

Michael Kay
Saxonica


However, I managed to make it work by compiling the child nodes and treating the expressions the same way as the attributes in the samples:

public class GuiMessageDialog extends ExtensionInstruction {

        @Override
        protected void prepareAttributes() throws XPathException {
                // no attributes
        }

        @Override
        public boolean mayContainSequenceConstructor() {
                return true;
        }

        @Override
        public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException {
                AxisIterator childIterator = iterateAxis(AxisInfo.CHILD);

                final List<Expression> childExprList = new LinkedList<Expression>();
                NodeInfo child = childIterator.next();
                while (child != null) {
                        if (child instanceof StyleElement) {
                                final Expression childExpr = ((StyleElement)child).compile(exec, decl);
                                if (childExpr != null) {
                                        childExprList.add(childExpr);
                                }
                        }
                        child = childIterator.next();
                }
                return new MessageDialogInstruction(childExprList);
        }

        private static class MessageDialogInstruction extends SimpleExpression {

                public MessageDialogInstruction(List<Expression> childExprList) {
                        setArguments(childExprList.toArray(new Expression[childExprList.size()]));
                }

                public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
                        String textString = "";
                        for (int i = 0; i < arguments.length; ++i) {
                                SequenceIterator iterator = arguments[i].iterate();
                                Item item = iterator.next();
                                while (item != null) {
                                        textString += item.getStringValue();
                                        item = iterator.next();
                                }
                        }

                        JOptionPane.showMessageDialog(
                                        (Frame)PluginWorkspaceProvider.getPluginWorkspace().getParentFrame(),
                                        textString,
                                        "Message",
                                        JOptionPane.PLAIN_MESSAGE);

                        return EmptySequence.getInstance();
                }

                public int getImplementationMethod() {
                        return Expression.EVALUATE_METHOD;
                }

                public String getExpressionType() {
                        return "gui:message-dialog";
                }
        }

}

Is this the correct way?

Patrik




Von:        Michael Kay <[hidden email]>
An:        Mailing list for the SAXON XSLT and XQuery processor <[hidden email]>,
Datum:        11.05.2015 15:00
Betreff:        Re: [saxon] processing content of extension instruction




Your extension instruction will implement the class ExtensionInstruction, which implements StyleElement, which implements ElementImpl and therefore NodeInfo. It is simply a node on the stylesheet tree. So you can call things like iterateAxis() to find the children, or getStringValue() to get the string value.

Michael Kay
Saxonica


On 11 May 2015, at 10:42, [hidden email] wrote:

Hi,

I already implemented some extension instructions, for instance gui:message-dialog (working only when called from within oxygen). Now I'd like to allow the text to be specified as the content of this element rather than in the text attribute. Unfortunately, I could not figure out how to process the content nodes. (I used getStringContent() at first, which works for <xsl:text> but of course not for other instructions like <xsl:value-of>). Since I could not find any samples for how to process the content (beside StyleElement) of extension instructions, could you give me some hints how to do this?


Thanks and regards,


Patrik


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:
Volker Sonnenburg
Heiko Beermann

------------------------------------------------------------------
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 distributionof the material in this e-mail is strictly forbidden.


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help