Page 1 of 1
href to a specific node
Posted: Mon Nov 02, 2015 12:53 pm
by MaNI
I have XML with content in it similar to e.g.
I am trying to link to this from another XML document which has XML like:
Code: Select all
<xr refdoc="foo.xml" ref="C10024"></xr>
I use CSS 'content' with 'oxy_xpath' to display the data from the other document inside the xr when using Author mode, this works great.
Now I want to have oXygen Author mode actually take the user to the target when clicking in the content.
I've added the following CSS which correctly takes the user to the right document:
However I can't figure out how to take them to the right place in the document:
I can't find any proper documentation on what oXygen can do with hrefs in terms of extra data coming after '#' or '?' so I've tried e.g.:
Code: Select all
link: oxy_concat(oxy_xpath("@refdoc"),"#",attr(ref));
and:
Code: Select all
link: oxy_concat(oxy_xpath("@refdoc"),"?rid=",attr(ref));
and various other combinations but can't get anything to work.
Is there some way to achieve this?
Re: href to a specific node
Posted: Tue Nov 03, 2015 12:26 pm
by alex_jitianu
Hello,
The default implementation for locating elements works with:
- ID scheme: file:/.../foo.xml#my_id
- XInclude element scheme : element(/1/2)
That being said, if @rid is is declared as having ID type then you can use this rule:
Code: Select all
xr {
link: oxy_url(attr(refdoc)) "#" attr(ref);
content: attr(ref);
}
If @rid is not declared is not an ID then you can use the XInclude element scheme, like this:
Code: Select all
xr {
link: oxy_url(attr(refdoc)) "#" "element("
oxy_xpath( oxy_concat("concat('/', string-join(for $node in (doc('", oxy_url(attr(refdoc)), "')//*:Node[@rid='", attr(ref), "'])[1]/ancestor-or-self::* return xs:string(count($node/preceding-sibling::*) + 1), '/'))" ) )
")";
content: attr(ref);
}
Best regards,
Alex
Re: href to a specific node
Posted: Wed Nov 04, 2015 9:35 am
by MaNI
Okay, switching type to XS:ID appears to have worked thanks.
Re: href to a specific node
Posted: Wed Nov 04, 2015 9:40 am
by MaNI
Note - I don't know if this is an oXygen bug or something else, but if the target document is not already open in Author mode then the part after the # does not work (i.e. it doesn't scroll to the correct place) - if trying a second time (once the target document is already open in Author mode) then it works as expected.
Re: href to a specific node
Posted: Wed Nov 04, 2015 10:38 am
by alex_jitianu
Hello,
Strange. I've tested myself on some sample files and in my case the node was selected no matter if the target file was already open or not. If you contact us on email
support@oxygenxml.com I can send you some samples of mine and perhaps you can also send me some samples to reproduce the behavior.
Best regards,
Alex
Re: href to a specific node
Posted: Wed Nov 04, 2015 1:10 pm
by MaNI
Unfortunately I've run into some other limitations when trying to use xs:ID so I am trying now the second approach (Xinclude) I get the following error when clicking on the link.
Code: Select all
The application detected an error that is not automatically handled. It is possible that this error is not critical and the application may continue to work normally but our recommendation is to report the error and restart the application. If the application has become unstable and cannot be closed normally, you can use the Force Quit button from this dialog. Be aware that by doing this you will lose all unsaved changes in the opened documents.
Here are the error details:
[ Link opener: C:\Users\m\Desktop\AWS\Import\Output\5.xml ] - java.lang.ArrayIndexOutOfBoundsException: 0
java.lang.ArrayIndexOutOfBoundsException: 0
at ro.sync.ecss.extensions.commons.XPointerElementLocator.<init>(Unknown Source)
at ro.sync.ecss.extensions.commons.DefaultElementLocatorProvider.getElementLocator(Unknown Source)
at ro.sync.exml.editor.xmleditor.sb.goToReferenceInternal(Unknown Source)
at ro.sync.exml.editor.nc.goToReference(Unknown Source)
at ro.sync.exml.editor.nd.icl(Unknown Source)
at ro.sync.exml.editor.nd.ael(Unknown Source)
at ro.sync.exml.editor.nd.open(Unknown Source)
at ro.sync.exml.e.v.c(Unknown Source)
at ro.sync.exml.e.v.d(Unknown Source)
at ro.sync.exml.editor.xmleditor.pageauthor.p.open(Unknown Source)
at ro.sync.exml.editor.b.c.v$1.szc(Unknown Source)
at ro.sync.ui.application.kb.run(Unknown Source)
at ro.sync.ui.application.kb.start(Unknown Source)
at ro.sync.exml.editor.b.c.v.g(Unknown Source)
at ro.sync.ecss.component.h.k.c(Unknown Source)
at ro.sync.ecss.component.n.mouseEvent(Unknown Source)
at ro.sync.exml.view.l$2.mouseClicked(Unknown Source)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Re: href to a specific node
Posted: Wed Nov 04, 2015 1:12 pm
by MaNI
Sorry, nevermind - I see that it uses the element name 'Node' which I of course need to change to match my actual document.
All working well now thanks.
Re: href to a specific node
Posted: Fri Nov 06, 2015 4:24 pm
by MaNI
Another question:
Code: Select all
link: oxy_url(attr(refdoc)) "#" "element("
oxy_xpath( oxy_concat("concat('/', string-join(for $node in (doc('", oxy_url(attr(refdoc)), "')//*:Node[@rid='", attr(ref), "'])[1]/ancestor-or-self::* return xs:string(count($node/preceding-sibling::*) + 1), '/'))" ) )
")";
This slows the program to a crawl (and eventually shows an out of memory exception) if refdoc is not yet set (when inserting a new blank Node) - is there a way to not have the link evaluated unless the content is not empty or something similar to avoid this?
Re: href to a specific node
Posted: Fri Nov 06, 2015 9:58 pm
by alex_jitianu
Hello,
Quite an unexpected behavior...but if you say the situation happens only when @refdoc is not set (or empty) you can filter this particular situation through the CSS selector:
Code: Select all
xr[refdoc]:not([refdoc=""]) {
link: oxy_url(attr(refdoc)) "#" "element("
oxy_xpath( oxy_concat("concat('/', string-join(for $node in (doc('", oxy_url(attr(refdoc)), "')//*:Node[@rid='", attr(ref), "'])[1]/ancestor-or-self::* return xs:string(count($node/preceding-sibling::*) + 1), '/'))" ) )
")";
content: attr(ref);
}
If you still get the slow and OutOfMemory, perhaps you can send us some samples on
support@oxygenxml.com
Best regards,
Alex