XInclude+XPointer: selection by name doesn't work

Discussion in 'XML' started by Ivan_G_S, Feb 7, 2008.

  1. Ivan_G_S

    Ivan_G_S Guest

    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!
     
    Ivan_G_S, Feb 7, 2008
    #1
    1. Advertising

  2. 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
     
    Joseph Kesselman, Feb 7, 2008
    #2
    1. Advertising

  3. 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 !
     
    Philippe Poulard, Feb 7, 2008
    #3
  4. 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/
     
    Martin Honnen, Feb 7, 2008
    #4
  5. Ivan_G_S

    Ivan_G_S Guest

    On Feb 7, 7:21 pm, Martin Honnen <> 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
     
    Ivan_G_S, Feb 7, 2008
    #5
  6. 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
     
    Joseph Kesselman, Feb 7, 2008
    #6
  7. Ivan_G_S

    Ivan_G_S Guest

    On Feb 7, 2:02 pm, Joseph Kesselman <>
    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 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
     
    Ivan_G_S, Feb 7, 2008
    #7
  8. Possible insight: What happens when you try searching for blupp rather
    than root?

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Feb 7, 2008
    #8
  9. Ivan_G_S

    Ivan_G_S Guest

    On Feb 7, 9:07 pm, Joseph Kesselman <>
    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 ;)
     
    Ivan_G_S, Feb 7, 2008
    #9
  10. Ivan_G_S a écrit :
    > On Feb 7, 7:21 pm, Martin Honnen <> 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-->
    <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

    >
    > thanx



    --
    Cordialement,

    ///
    (. .)
    --------ooO--(_)--Ooo--------
    | Philippe Poulard |
    -----------------------------
    http://reflex.gforge.inria.fr/
    Have the RefleX !
     
    Philippe Poulard, Feb 8, 2008
    #10
  11. Ivan_G_S wrote:

    > 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.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Feb 8, 2008
    #11
  12. Ivan_G_S wrote:

    > 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.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Feb 8, 2008
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shay
    Replies:
    0
    Views:
    899
  2. tintagel

    using xpointer in html

    tintagel, Apr 1, 2006, in forum: HTML
    Replies:
    3
    Views:
    447
    tintagel
    Apr 3, 2006
  3. DV
    Replies:
    1
    Views:
    2,844
    Martin Honnen
    Apr 19, 2004
  4. SL
    Replies:
    0
    Views:
    541
  5. RolfK
    Replies:
    0
    Views:
    1,071
    RolfK
    Feb 6, 2009
Loading...

Share This Page