Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XInclude+XPointer: selection by name doesn't work

Reply
Thread Tools

XInclude+XPointer: selection by name doesn't work

 
 
Ivan_G_S
Guest
Posts: n/a
 
      02-07-2008
hello!

i am using saxon 9 as xslt processor.

i am trying to include a part of an xml document into another (more
precisely: into an xslt).
selection by name doesn't work, while selection by node number (using
element()) does.

the to-be-included document is something like:

<root>
<node>bla</node>
</root>

this works:
<xi:include href="to-be-included.xml" xpointer="element(/1/1)"/>

while this fails:
<xi:include href="to-be-included.xml" xpointer="/root"/>
error is: the NCName of the ShortHand pointer '/root' is invalid.

also this fails:
<xi:include href="to-be-included.xml" xpointer="root"/>
error is: xpointer resolution unsuccessful.

is saxon missing some xpointer featuers?
or am i missing some xpointer understanding?

thanx in advice!
 
Reply With Quote
 
 
 
 
Joseph Kesselman
Guest
Posts: n/a
 
      02-07-2008
Ivan_G_S wrote:
> selection by name doesn't work


Generally that means you've forgotten to allow for namespaces.

> the to-be-included document is something like:


What is it _exactly_ like?

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
 
 
 
Philippe Poulard
Guest
Posts: n/a
 
      02-07-2008
Ivan_G_S a écrit :
> hello!
>
> i am using saxon 9 as xslt processor.
>
> i am trying to include a part of an xml document into another (more
> precisely: into an xslt).
> selection by name doesn't work, while selection by node number (using
> element()) does.
>
> the to-be-included document is something like:
>
> <root>
> <node>bla</node>
> </root>
>
> this works:
> <xi:include href="to-be-included.xml" xpointer="element(/1/1)"/>
>
> while this fails:
> <xi:include href="to-be-included.xml" xpointer="/root"/>
> error is: the NCName of the ShortHand pointer '/root' is invalid.


try this :
<xi:include href="to-be-included.xml" xpointer="xpointer(/root)"/>

notice that although you have to specify the xpointer() scheme, you
won't have necessary access to all xpointer features ; XInclude engines
used to support only XPath expressions (and sometimes a smaller subset
of XPath), I don't know an engine that support all XPointer expressions
(ranges, point, and XPointer specific functions that look like somewhat
deprecated)

notice that if your XML uses namespaces, you also have to use the
xmlns() scheme in addition to the xpointer() scheme

>
> also this fails:
> <xi:include href="to-be-included.xml" xpointer="root"/>
> error is: xpointer resolution unsuccessful.
>
> is saxon missing some xpointer featuers?
> or am i missing some xpointer understanding?
>
> thanx in advice!



--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      02-07-2008
Ivan_G_S wrote:

> i am using saxon 9 as xslt processor.
>
> i am trying to include a part of an xml document into another (more
> precisely: into an xslt).
> selection by name doesn't work, while selection by node number (using
> element()) does.
>
> the to-be-included document is something like:
>
> <root>
> <node>bla</node>
> </root>
>
> this works:
> <xi:include href="to-be-included.xml" xpointer="element(/1/1)"/>
>
> while this fails:
> <xi:include href="to-be-included.xml" xpointer="/root"/>
> error is: the NCName of the ShortHand pointer '/root' is invalid.


If you want to use a shorthand pointer without a scheme prefix then the
pointer should be an NCName with the id attribute value of an element
you want to point to.


> is saxon missing some xpointer featuers?


The documentation here
<URL:http://www.saxonica.com/documentation/using-xsl/commandline.html>
suggests that the XInclude support is handled by the Xerces XML parser
so you will have to find out which XInclude features Xerces supports.



--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
Ivan_G_S
Guest
Posts: n/a
 
      02-07-2008
On Feb 7, 7:21*pm, Martin Honnen <(E-Mail Removed)> wrote:
> The documentation here
> <URL:http://www.saxonica.com/documentation/using-xsl/commandline.html>
> suggests that the XInclude support is handled by the Xerces XML parser
> so you will have to find out which XInclude features Xerces supports.


i quote from here: http://xerces.apache.org/xerces2-j/faq-xinclude.html

???: Does the XInclude processor support XPointer?
Yes. The XInclude processor supports the XPointer Framework and the
XPointer element() Scheme. The XPointer xpointer() Scheme is currently
not supported.

???: What types of IDs are currently supported for XPointers?
For shorthand pointers and element() XPointers, currently only DTD-
determined IDs are supported. schema-determined IDs may be supported
in a future release.

i am sorry, i'm not a schema expert. does it mean that there is NO
possibility to select elements by name?

does anyone know if there are (for this case) 'better' xslt
transformers than saxon?

thanx
 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      02-07-2008
Ivan_G_S wrote:
> i am sorry, i'm not a schema expert. does it mean that there is NO
> possibility to select elements by name?


No, that has to do with attributes declared as being of type ID. Both
schemas and DTDs have that concept, but unfortunately the XML Infoset
considers these two distinct groups of IDs.

Irrelevant to your question.

You haven't given us enough data, but I'm still betting on a namespace
error.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
Ivan_G_S
Guest
Posts: n/a
 
      02-07-2008
On Feb 7, 2:02*pm, Joseph Kesselman <(E-Mail Removed)>
wrote:
> You haven't given us enough data, but I'm still betting on a namespace
> error.


ok, i try again

i call saxon 9 this way:
saxon versionmsgff -xin -o 3-output-data.xml 1-initial-data.xml 2-
stylesheet.xsl

file "1-include-this.xml"
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root>
<node name="blupp"/>
</root>

file "1-initial-data.xml"
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root xmlnsi="http://www.w3.org/2001/XInclude">
<node name="blabla"/>
<xi:include href="1-include-this.xml" xpointer="element(/1)"/>
</root>

file "2-stylesheet.xsl"
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlnssl="http://www.w3.org/1999/XSL/
Transform">
<xslutput method="xml"/>
<xsl:template match="/root">
<root>
<xsl:apply-templates/>
</root>
</xsl:template>
<xsl:template match="node">
<node>
a node named <xsl:value-of select="@name"/>
</node>
</xsl:template>
</xsl:stylesheet>

file "3-output-data.xml"
<?xml version="1.0" encoding="UTF-8"?><root>
<node>a node named blabla</node>
<node>a node named blupp</node>
</root>

good! so this works with element(/1), but i want to be able to do it
BY NAME, not by id, not by element number.
(this would make sence for bigger examples, where i don't know the
element number, and where are no IDs)

what happens if i change element(/1) to something else?

----------------
xpointer="root" gives:
Warning: org.xml.sax.SAXParseException: Include operation failed,
reverting to fallback. Resource
error reading file as XML (href='1-include-this.xml'). Reason:
XPointer resolution unsuccessful.
----------------
xpointer="/root" gives
Warning: org.xml.sax.SAXParseException: Include operation failed,
reverting to fallback. Resource
error reading file as XML (href='1-include-this.xml'). Reason:
InvalidShortHandPointer:
The NCName of the ShortHand Pointer '/root' is invalid.
----------------
xpointer="xpointer(root)" gives:
Warning: org.xml.sax.SAXParseException: SchemeUnsupported: The
XPointer scheme 'xpointer' is not supported.
Warning: org.xml.sax.SAXParseException: Include operation failed,
reverting to fallback. Resource
error reading file as XML (href='1-include-this.xml'). Reason:
XPointer resolution unsuccessful.

thanx
 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      02-07-2008
Possible insight: What happens when you try searching for blupp rather
than root?

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
Ivan_G_S
Guest
Posts: n/a
 
      02-07-2008
On Feb 7, 9:07*pm, Joseph Kesselman <(E-Mail Removed)>
wrote:
> Possible insight: What happens when you try searching for blupp rather
> than root?


same as xpointer="root":
Warning: org.xml.sax.SAXParseException: Include operation failed,
reverting to fallback. Resource
error reading file as XML (href='1-include-this.xml'). Reason:
XPointer resolution unsuccessful.

what i need is, in my opinion, nothing special, nothing unusual: i
want an element identified by name. so i suppose there must be a
simple way to do this. i wish someone could reveal this 'secret' to
me
 
Reply With Quote
 
Philippe Poulard
Guest
Posts: n/a
 
      02-08-2008
Ivan_G_S a écrit :
> On Feb 7, 7:21 pm, Martin Honnen <(E-Mail Removed)> wrote:
>> The documentation here
>> <URL:http://www.saxonica.com/documentation/using-xsl/commandline.html>
>> suggests that the XInclude support is handled by the Xerces XML parser
>> so you will have to find out which XInclude features Xerces supports.

>
> i quote from here: http://xerces.apache.org/xerces2-j/faq-xinclude.html
>
> ???: Does the XInclude processor support XPointer?
> Yes. The XInclude processor supports the XPointer Framework and the
> XPointer element() Scheme. The XPointer xpointer() Scheme is currently
> not supported.
>
> ???: What types of IDs are currently supported for XPointers?
> For shorthand pointers and element() XPointers, currently only DTD-
> determined IDs are supported. schema-determined IDs may be supported
> in a future release.
>
> i am sorry, i'm not a schema expert. does it mean that there is NO
> possibility to select elements by name?
>
> does anyone know if there are (for this case) 'better' xslt
> transformers than saxon?


this is not the fault to the transformer, but to the XInclude engine
involved (things are separated)

I have my own XInclude implementation in RefleX
(http://reflex.gforge.inria.fr/) that work both with SAX and DOM ;
unfortunately, I have injected a small bug in the last release :
sometimes there is a trailing space added at the end of the flow to
include ; it can be important for you, but you can also deal with it

there are also other limitations that can occur on very complex cases,
but the xpointer() scheme is rather well supported (although it is
reduced to XPath) ; if you use XPath expressions that use a backward axe
(preceding and preceding-sibling, ancestor is supported), then you will
have to specify a DOM parsing, otherwise, a SAX parsing is also
supported even when using XPath
see http://reflex.gforge.inria.fr/tests-xinclude.html

of course if you want to make a pipeline that make first an xinclusion
then an XSLT transformation with Saxon, you can (you just have to plug
Saxon in JAXP like specified in the Java or perhaps Saxon documentation
; google for it)


in reflex, a parse->XInclude->XSLT pipeline can be written like this :

<!--get an XInclude filter :
the URI given act like a key to get the filter-->
<xclarse-filter name="xinclude"
source="http://www.w3.org/2001/XInclude"/>
<!--get the XSLT-->
<xclarse-stylesheet name="xslt"
source="file:///path/to/my/stylesheet.xsl"/>

<!--connect a pipeline-->
<xclarse name="input" source="file:///path/to/my/source.xml"
style="stream" validate="yes"/>
<xcl:filter name="included" source="{ $input }" filter="{ $xinclude }"/>
<xcl:transform source="{ $included }"
output="file:///path/to/my/output.html" stylesheet="{ $xslt }"/>

here is a complete runnable example that catch and report errors :
http://reflex.gforge.inria.fr/tests/...y-sequence.xcl

tell me if you have some troubles

>
> thanx



--
Cordialement,

///
(. .)
--------ooO--(_)--Ooo--------
| Philippe Poulard |
-----------------------------
http://reflex.gforge.inria.fr/
Have the RefleX !
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
selection structure nested within another selection structure 4Ankit@gmail.com Javascript 1 12-07-2006 11:47 AM
JTable with row selection, but no cell selection Simon Niederberger Java 2 01-07-2005 04:17 PM
JS comparing innerHTML to text selection (window.getSelection() /document.selection) Andrew Crowe HTML 1 09-13-2004 02:22 PM
How to change a range selection to text selection? Loebb Javascript 0 02-23-2004 02:12 PM
HOWTO autopost the selection list upon selection curiousity ASP .Net Mobile 0 11-21-2003 12:57 AM



Advertisments