喜欢for
,sum
,if
,intersect
...如果没有,或者不完全,我在哪里可以找到详细信息?如果确实如此,我在哪里可以找到官方确认?
我正在努力找到在休斯顿工作的员工,但项目所在的部门并不在休斯顿.我试图在FLWOR表达式的这个示例之后对表达式进行建模,但是查询没有返回任何内容,它应该返回结果.
编辑:这是输入.
xquery
let $doc := doc("~path/company.xml")
for $e in $doc//employee,
$d in $doc//department,
$p in $doc//projects
where $d/locations[location!="Houston"]
and $p/project[plocations="Houston"]
return <e>{$e/fname}{$e/lname}{$e/address}</e>
/
Run Code Online (Sandbox Code Playgroud) 我有一个XML文件,我需要将其转换为XQuery.考虑一组简单的XML:
books[book]
book[@isbn, title, descrption]
Run Code Online (Sandbox Code Playgroud)
例如:
<books>
<book isbn="1590593049">
<title>Extending Flash MX 2004</title>
<description>
Using javascript alongwith actionscript 3.0 and mxml.</description>
</book>
<book isbn="0132149184">
<title>Java Software Solutions</title>
<description>
Complete book full of case studies on business solutions and design concepts while building mission critical
business applications.
</description>
</book>
Run Code Online (Sandbox Code Playgroud)
如何使用XQuery将其转换为CSV格式?CSV由Microsoft Excel使用,
所以它将用逗号(,)字符分隔,特殊字符应该被转义.
我试图在python中使用以下xpath查询
from lxml.html.soupparser import fromstring
root = fromstring(inString)
nodes = root.xpath(".//p3[matches(.,'ABC')]//preceding::p2//p3")
Run Code Online (Sandbox Code Playgroud)
但它给了我错误
nodes = root.xpath(".//p3[matches(.,'ABC')]//preceding::p2//p3")
File "lxml.etree.pyx", line 1507, in lxml.etree._Element.xpath (src\lxml\lxml.etree.c:52198)
File "xpath.pxi", line 307, in lxml.etree.XPathElementEvaluator.__call__ (src\lxml\lxml.etree.c:152124)
File "xpath.pxi", line 227, in lxml.etree._XPathEvaluatorBase._handle_result (src\lxml\lxml.etree.c:151097)
File "xpath.pxi", line 212, in lxml.etree._XPathEvaluatorBase._raise_eval_error (src\lxml\lxml.etree.c:150896)
lxml.etree.XPathEvalError: Unregistered function
Run Code Online (Sandbox Code Playgroud)
我如何在这里使用XPath 2.0函数与lxml?
澄清
我之前使用的是contains函数
nodes = root.xpath(".//p3[contains(text(),'ABC')]//preceding::p2//p3")
Run Code Online (Sandbox Code Playgroud)
问题是我的xml在文本中有换行符和空格,因此我尝试使用类似的东西
nodes = root.xpath(".//p3[contains(normalize-space(),'ABC')]//preceding::p2//p3")
Run Code Online (Sandbox Code Playgroud)
但这没有效果.最后我尝试使用匹配功能,我得到了错误.
示例XML
<doc>
<q></q>
<p1>
<p2 dd="ert" ji="pp">
<p3>1</p3>
<p3>2</p3>
<p3>
ABC
</p3>
<p3>3</p3>
</p2>
<p2 dd="ert" ji="pp">
<p3>4</p3>
<p3>5</p3>
<p3>ABC</p3>
<p3>6</p3>
</p2> …
Run Code Online (Sandbox Code Playgroud) 在Stack Overflow上研究XPath问题答案的细节时,我遇到了XPath 1.0和2.0之间的差异,我找不到理由.
我试图了解.
真正的意义.
.
是.的缩写self::node()
.这两个self
和node
一清二楚给我..
主要表达式是" 1])或原子值(如表达式(1到100)[.mod 5 eq 0]).">上下文项表达式 ".缩写语法部分明确指出作为注释.改变的理由是什么?有没有之间的差异.
和self::node()
XPath 2.0中?
从规范本身来看,改变的意图对我来说并不清楚.我尝试使用谷歌搜索关键字,如点或句点,主要表达和基本原理.
我正在进行XSLT转换,我发现了一个我无法回答的有趣问题:
child::*
和之间有什么区别child::node()
?
我想创建一个条件,在其中我将children元素的数量分隔为1,在这种情况下:
<xsl:if test="parent[count(child::*) eq 1])">
Run Code Online (Sandbox Code Playgroud)
VS
<xsl:if test="parent[count(child::node()) eq 1])">
Run Code Online (Sandbox Code Playgroud)
有什么区别?
我发布了另一个问题作为它的一个方面.我被告知要澄清这个问题,但这个问题已经很长很复杂了,所以我创建了一个新问题.
我想知道在XPath表达式测试中是否存在引用当前节点属性的标准方法.
例如,请考虑以下XSLT
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="potato/stem[eye]">
In session <xsl:value-of select="@sessionID"/>, the potato had <xsl:value-of select="/potato/stem[@sessionID=@sessionID][scc]/scc/@leafnumber"/> s.c.c. leaves.
</xsl:for-each>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
(此问题底部的XML源.)(请注意,for-each引用了类型为[eye]的节点,但请求的第二个值引用了类型为stem [scc]的节点,这些节点位于源XML树的不同分支上.)
现在,显然,"@ sessionID = @sessoinID"部分大部分都没有意义,因为XPath将其视为"节点的sessionID属性的值应该等于......节点的sessionID属性的值."
但我想说的是"测试以确保该节点的seesionID属性的值(XPath表达式中的那个)与我所在的/ stem [eye]节点的节点的sessionID相同马上."
我无法使用变量执行此操作,因为不允许在for-each子句中声明变量.
作为参考,这是XML源.它的结构不是人们想要的,但它是我必须要合作的.
<?xml version="1.0" encoding="utf-8"?>
<potato>
<stem sessionID="1">
<eye number = "25"/>
</stem>
<stem sessionID="3">
<eye number = "33"/>
</stem>
<stem sessionID="1">
<scc leafnumber = "234" />
</stem>
<stem sessionID="2">
<scc leafnumber = "433"/>
</stem>
<stem sessionID="3">
<scc leafnumber = "463"/> …
Run Code Online (Sandbox Code Playgroud) 我有一个XML文档:
<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
<fruits>
<fruit id="1">
<title>I like pineapples</title>
<description> a tropical plant with edible multiple fruit consisting of coalesced berries</description>
</fruit>
<fruit id="2">
<title>I like watermelons</title>
<description>has a smooth exterior rind (green, yellow and sometimes white) and a juicy, sweet interior flesh</description>
</fruit>
</fruits>
</document>
Run Code Online (Sandbox Code Playgroud)
如何检查title
元素是否包含'菠萝',以便我只能显示description
该特定的fruit
?
这是我的XSLT转换:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" doctype-public="-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
doctype-system="http://www.wapforum.org/DTD/xhtml-mobile10.dtd"/>
<xsl:template match="/">
<xsl:element name="html">
<xsl:element name="head">
<xsl:element name="title">Fruits</xsl:element>
</xsl:element>
<xsl:element …
Run Code Online (Sandbox Code Playgroud) 我想使用xpath检查xml中的节点是否包含空字符串/空格.我需要使用的xpath表达式是什么?
例如:
<p:insert_acc_data_file xmlns:p="http://ws.wso2.org/dataservice">
<p:Id>123</p:Id>
<p:Name></p:pName>
</p:insert_acc_data_file>
Run Code Online (Sandbox Code Playgroud)
如何检查Name节点是空的还是包含空格值?
我有以下 XML
<?xml version="1.0" encoding="UTF-8"?>
<stationary>
<textbook>
<name>test</name>
</textbook>
<notebook>
<books>
<name>test</name>
</books>
</notebook>
</stationary>
Run Code Online (Sandbox Code Playgroud)
我正在尝试获取所有name
元素,而不管它们在stationary
我曾尝试使用以下语法,但没有奏效:
stationary/*/name/text()
Run Code Online (Sandbox Code Playgroud)