Identity Transform

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

Identity Transform

Jorge Williams-2

Hello all,

Probably a dumb question, but can’t figure this out by looking at the Docs.

I have an XdmNode and want to send that to a Destination.  In the JAX-P API, I would create and Identity transformer and treat the XdmNode as a source — because I have a Destination and not a Result I can’t use that approach.  How do I accomplish this with the s9 API?

Thanks,

-jOrGe W.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
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: Identity Transform

Martin Honnen-2
On 19.01.2017 16:11, Jorge Williams wrote:

> Probably a dumb question, but can’t figure this out by looking at the Docs.
>
> I have an XdmNode and want to send that to a Destination.  In the JAX-P API, I would create and Identity transformer and treat the XdmNode as a source — because I have a Destination and not a Result I can’t use that approach.  How do I accomplish this with the s9 API?

Use
http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Serializer.html#serializeNode(net.sf.saxon.s9api.XdmNode)
after having created a Serializer from the Processor and set the
destination of the serializer.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
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: Identity Transform

Jorge Williams-2
Hey Martin,

I see you can set an OutputStream, a File, or a Writer to a serializer…but how do I set a net.sf.saxon.s9api.Destination?

I’ve been playing with an alternative approach :

I’ve had some success reaching into the Destination and passing the result of getReceiver to an IdentityTransform like this:

idTrans = (new net.sf.saxon.TransformerFactoryImpl).newTransformer()

idTrans.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "yes”)

idTrans.transform(src, dest.getReceiver(processor.getUnderlyingConfiguration()))

This works because the Receiver implements the Result interface.

The only issue I have now is that the result is not honoring the INDENT output property.

Any hints?

-jOrGe W.


> On Jan 19, 2017, at 10:31 AM, Martin Honnen <[hidden email]> wrote:
>
> On 19.01.2017 16:11, Jorge Williams wrote:
>
>> Probably a dumb question, but can’t figure this out by looking at the Docs.
>>
>> I have an XdmNode and want to send that to a Destination.  In the JAX-P API, I would create and Identity transformer and treat the XdmNode as a source — because I have a Destination and not a Result I can’t use that approach.  How do I accomplish this with the s9 API?
>
> Use
> http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Serializer.html#serializeNode(net.sf.saxon.s9api.XdmNode)
> after having created a Serializer from the Processor and set the
> destination of the serializer.
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
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: Identity Transform

Michael Kay
In reply to this post by Jorge Williams-2



> On 19 Jan 2017, at 15:11, Jorge Williams <[hidden email]> wrote:
>
>
> Hello all,
>
> Probably a dumb question, but can’t figure this out by looking at the Docs.
>
> I have an XdmNode and want to send that to a Destination.  In the JAX-P API, I would create and Identity transformer and treat the XdmNode as a source — because I have a Destination and not a Result I can’t use that approach.  How do I accomplish this with the s9 API?
>

There is a method Processor.writeXdmValue(XdmValue value, Destination destination)

An XdmNode is an XdmValue so you can use this method.

As Martin points out, for the special but common case where the Destination you want is a Serializer, you can use

Serializer.serializeXdmValue(value)

Michael Kay
Saxonica


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
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: Identity Transform

Michael Kay
>>
>
> There is a method Processor.writeXdmValue(XdmValue value, Destination destination)
>

Incidentally, the reason for this slightly clumsy design is that neither an XdmValue nor a Destination is guaranteed to give access to the Saxon Configuration object, and in general we need a Configuration to perform this operation. The Processor does always have a Configuration, so it needs to come into play. It was probably a mistake to allow classes such as DOMDestination and SAXDestination to be instantiated without supplying a Processor.

Michael Kay
Saxonica



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
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: Identity Transform

Jorge Williams-2
Hi Michael,

Thank you for the response.

Your suggestion works, but I lose indentation in the document.  I’ve experimented with setting setStripsWhiteSpace to NONE on the configuration, but that doesn’t help.

Let me take a step back and explain what I’m trying to do.

Have an XSLT that produces a result document which I want to send to Destination1  — Destination1 ends up either on disk or on the console and it’s essentially for debugging so it’s important that it gets formatted.   The XSLT  Sets <xsl:output indent="yes”/>

I want to send the document to Destination1 and then process it further in later stages of a pipeline.

My first attempt was to capture the Document with an XDMDest first, then send it to Destination1  then continue to process the document.

I tried 3 different methods  to do so:

1.  Transform to XDMDest then Processor.writeXdmValue setting the destination to Destination1

2.  Transform to XDMDest then create an Identity transform net.sf.saxon.TransformerFactoryImpl.newTransformer()  and do a transform sending the Destination1 Receiver as the Result.  Note that I set the OutputProperty of INDENT to “yes”

3.  Use a TeeDestination where I set Destination1 and the XDMDest as the targets

All of these methods lost indentation.

If I do a transform directly to Destination1 indentation works, but I lose the document for further processing.

Any thoughts?  I’m using Saxon-EE 9.7.0-8 - if that helps.

Thanks,

-jOrGe W.



> On Jan 20, 2017, at 6:25 PM, Michael Kay <[hidden email]> wrote:
>
>>>
>>
>> There is a method Processor.writeXdmValue(XdmValue value, Destination destination)
>>
>
> Incidentally, the reason for this slightly clumsy design is that neither an XdmValue nor a Destination is guaranteed to give access to the Saxon Configuration object, and in general we need a Configuration to perform this operation. The Processor does always have a Configuration, so it needs to come into play. It was probably a mistake to allow classes such as DOMDestination and SAXDestination to be instantiated without supplying a Processor.
>
> Michael Kay
> Saxonica
>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help 

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
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: Identity Transform

Michael Kay

> On 21 Jan 2017, at 21:03, Jorge Williams <[hidden email]> wrote:
>
> Hi Michael,
>
> Thank you for the response.
>
> Your suggestion works, but I lose indentation in the document.  I’ve experimented with setting setStripsWhiteSpace to NONE on the configuration, but that doesn’t help.
>
> Let me take a step back and explain what I’m trying to do.
>
> Have an XSLT that produces a result document which I want to send to Destination1  — Destination1 ends up either on disk or on the console and it’s essentially for debugging so it’s important that it gets formatted.   The XSLT  Sets <xsl:output indent="yes”/>
>
> I want to send the document to Destination1 and then process it further in later stages of a pipeline.

If the transformation output is anything other than a Serializer, then <xsl:output> on the stylesheet is ignored. This declaration is specifically an instruction to the serializer, and it's ignored if there isn't one.

To create a tree that contains the transformation output together with indentation whitespace, I think you're going to serialize and then re-parse (unless of course you write your own indentation transform).

But do you really need to? You say you need indentation for debugging purposes, so surely you can apply indentation at any point where you want to view a tree for human consumption? The indentation doesn't have to be present in the tree, it only has to be there in the formatted view of the tree.

Michael Kay
Saxonica


> My first attempt was to capture the Document with an XDMDest first, then send it to Destination1  then continue to process the document.
>
> I tried 3 different methods  to do so:
>
> 1.  Transform to XDMDest then Processor.writeXdmValue setting the destination to Destination1
>
> 2.  Transform to XDMDest then create an Identity transform net.sf.saxon.TransformerFactoryImpl.newTransformer()  and do a transform sending the Destination1 Receiver as the Result.  Note that I set the OutputProperty of INDENT to “yes”
>
> 3.  Use a TeeDestination where I set Destination1 and the XDMDest as the targets
>
> All of these methods lost indentation.
>
> If I do a transform directly to Destination1 indentation works, but I lose the document for further processing.
>
> Any thoughts?  I’m using Saxon-EE 9.7.0-8 - if that helps.
>
> Thanks,
>
> -jOrGe W.
>
>
>
>> On Jan 20, 2017, at 6:25 PM, Michael Kay <[hidden email]> wrote:
>>
>>>>
>>>
>>> There is a method Processor.writeXdmValue(XdmValue value, Destination destination)
>>>
>>
>> Incidentally, the reason for this slightly clumsy design is that neither an XdmValue nor a Destination is guaranteed to give access to the Saxon Configuration object, and in general we need a Configuration to perform this operation. The Processor does always have a Configuration, so it needs to come into play. It was probably a mistake to allow classes such as DOMDestination and SAXDestination to be instantiated without supplying a Processor.
>>
>> Michael Kay
>> Saxonica
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>> _______________________________________________
>> saxon-help mailing list archived at http://saxon.markmail.org/
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/saxon-help 
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
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: Identity Transform

Jorge Williams-2
(Inline)

> On Jan 21, 2017, at 5:18 PM, Michael Kay <[hidden email]> wrote:
>
>>
>> On 21 Jan 2017, at 21:03, Jorge Williams <[hidden email]> wrote:
>>
>> Hi Michael,
>>
>> Thank you for the response.
>>
>> Your suggestion works, but I lose indentation in the document.  I’ve experimented with setting setStripsWhiteSpace to NONE on the configuration, but that doesn’t help.
>>
>> Let me take a step back and explain what I’m trying to do.
>>
>> Have an XSLT that produces a result document which I want to send to Destination1  — Destination1 ends up either on disk or on the console and it’s essentially for debugging so it’s important that it gets formatted.   The XSLT  Sets <xsl:output indent="yes”/>
>>
>> I want to send the document to Destination1 and then process it further in later stages of a pipeline.
>
> If the transformation output is anything other than a Serializer, then <xsl:output> on the stylesheet is ignored. This declaration is specifically an instruction to the serializer, and it's ignored if there isn't one.


Shouldn’t a TeeDestination pass the instruction along? I guess that would mean that the TeeDestination would also have to be a Serializer??

This is enough to help me resolve the problem though,  I now set the OutputProperty of INDENT as soon as I create the serializer at the beginning of the process and don’t rely on <xsl:output indent=“yes”/>. That gives me the right behavior.

Thank you,

-jOrGe W.

>
> To create a tree that contains the transformation output together with indentation whitespace, I think you're going to serialize and then re-parse (unless of course you write your own indentation transform).
>
> But do you really need to? You say you need indentation for debugging purposes, so surely you can apply indentation at any point where you want to view a tree for human consumption? The indentation doesn't have to be present in the tree, it only has to be there in the formatted view of the tree.
>
> Michael Kay
> Saxonica
>
>
>> My first attempt was to capture the Document with an XDMDest first, then send it to Destination1  then continue to process the document.
>>
>> I tried 3 different methods  to do so:
>>
>> 1.  Transform to XDMDest then Processor.writeXdmValue setting the destination to Destination1
>>
>> 2.  Transform to XDMDest then create an Identity transform net.sf.saxon.TransformerFactoryImpl.newTransformer()  and do a transform sending the Destination1 Receiver as the Result.  Note that I set the OutputProperty of INDENT to “yes”
>>
>> 3.  Use a TeeDestination where I set Destination1 and the XDMDest as the targets
>>
>> All of these methods lost indentation.
>>
>> If I do a transform directly to Destination1 indentation works, but I lose the document for further processing.
>>
>> Any thoughts?  I’m using Saxon-EE 9.7.0-8 - if that helps.
>>
>> Thanks,
>>
>> -jOrGe W.
>>
>>
>>
>>> On Jan 20, 2017, at 6:25 PM, Michael Kay <[hidden email]> wrote:
>>>
>>>>>
>>>>
>>>> There is a method Processor.writeXdmValue(XdmValue value, Destination destination)
>>>>
>>>
>>> Incidentally, the reason for this slightly clumsy design is that neither an XdmValue nor a Destination is guaranteed to give access to the Saxon Configuration object, and in general we need a Configuration to perform this operation. The Processor does always have a Configuration, so it needs to come into play. It was probably a mistake to allow classes such as DOMDestination and SAXDestination to be instantiated without supplying a Processor.
>>>
>>> Michael Kay
>>> Saxonica
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Check out the vibrant tech community on one of the world's most
>>> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>>> _______________________________________________
>>> saxon-help mailing list archived at http://saxon.markmail.org/
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/saxon-help 
>>
>> ------------------------------------------------------------------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>> _______________________________________________
>> saxon-help mailing list archived at http://saxon.markmail.org/
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Loading...