XInclude+XPointer: selection by name doesn't work

I

Ivan_G_S

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!
 
P

Philippe Poulard

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 !
 
M

Martin Honnen

Ivan_G_S said:
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.
 
I

Ivan_G_S

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
 
J

Joseph Kesselman

Ivan_G_S said:
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.
 
I

Ivan_G_S

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 versionmsg:eek:ff -xi:eek:n -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 xmlns:xi="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" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:eek:utput 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
 
J

Joseph Kesselman

Possible insight: What happens when you try searching for blupp rather
than root?
 
I

Ivan_G_S

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 ;)
 
P

Philippe Poulard

Ivan_G_S a écrit :
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-->
<xcl:parse-filter name="xinclude"
source="http://www.w3.org/2001/XInclude"/>
<!--get the XSLT-->
<xcl:parse-stylesheet name="xslt"
source="file:///path/to/my/stylesheet.xsl"/>

<!--connect a pipeline-->
<xcl:parse 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/xunit/xop/5.1/apply-sequence.xcl

tell me if you have some troubles


--
Cordialement,

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

Martin Honnen

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

It has not much to do with Saxon and XSLT at all, it it a question of
XInclude and XPointer support.
 
M

Martin Honnen

Ivan_G_S said:
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?

The above means you can use DTD-determined IDs and you can use the
element() scheme in your xpointer attribute. Selecting elements by
element name is not supported I think.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top