Menu

Saxon 9.3 failed for process wild character *

Help
2011-08-24
2012-10-08
  • Jianming Xu

    Jianming Xu - 2011-08-24

    fail.xq:
    for $item in doc("items.xml")//items//item
    where $item//description="Red*"
    return $item//itemno

    Result:
    C:\saxonhe>java -cp saxon9he.jar net.sf.saxon.Query -t -s:items.xml -q:fail.xq
    Saxon-HE 9.3.0.4J from Saxonica
    Java version 1.6.0-rc
    Analyzing query from fail.xq
    Analysis time: 172 milliseconds
    Processing file:/C:/saxonhe/items.xml
    Source document ignored - query does not access the context item
    URIResolver.resolve href="items.xml" base="file:/C:/saxonhe/fail.xq"
    Using parser
    com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser

    Building tree for file:/C:/saxonhe/items.xml using class
    net.sf.saxon.tree.tiny.
    TinyBuilder
    Tree built in 15 milliseconds
    Tree size: 28 nodes, 59 characters, 0 attributes
    <?xml version="1.0" encoding="UTF-8"?>Execution time: 78ms
    Memory used: 4403992

     
  • Jianming Xu

    Jianming Xu - 2011-08-24

    items.xml:
    <items>
    <item>
    <itemno>1001</itemno>
    <description>Red Bicycle</description>
    <price>400</price>
    </item>
    <item>
    <itemno>1002</itemno>
    <description>Red Car</description>
    <price>5000</price>
    </item>
    </items>

     
  • Michael Kay

    Michael Kay - 2011-08-24

    Firstly, Saxon does not support the XQuery Full-Text Option.

    Secondly, even if it did, your syntax is wrong: wildcards are not recognized
    unless you have enabled this option, and the wildcard must be written "."
    rather than "
    ".

    You can achieve what you are trying to do here using regular expressions

    (matches(., "Red.*")
    

    or by using the starts-with function

    (starts-with(., "Red"))
    

    . Of course, unlike Full Text, these operate naively on the characters in the
    source document, rather than doing any intelligent linguistic stemming.