Saxon Xpath namespace

不打扰是莪最后的温柔 提交于 2019-12-11 03:32:45

问题


Given the following xml:

<Document xmlns="urn:company.com:catalog.01" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <book>
        <author>Wells</author>
    </book>
</Document>

With Xerces the following xpath query works:

//urn:company.com:catalog.01:author

When I use Saxon (v 8.7) I a StaticError with message 'Invalid QName local part {company.com:catalog....}'.

What should the Xpath query look like to get the value of author?


回答1:


Xerces should not allow an XPath expression like

//urn:company.com:catalog.01:author 

XPath is XML Names compliant, so a : (colon) in a QName divides the prefix part from local name part of a QName.

There is no syntax in XPath to use the full expanded QName in name test:

You could use

//*[local-name()='author'][namespace-uri()='urn:company.com:catalog.01']



回答2:


You didn't post your XSL file. I went through this recently, and the solution was to make sure the xsl file has a line like:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:c="urn:company.com:catalog.01">

Then your references to elements in the xml file are prefixed with "c:":

//c:author


来源:https://stackoverflow.com/questions/4399552/saxon-xpath-namespace

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!