在进行考试练习时难以理解 XML 中的“=>”语法。在网上搜索了它,但找不到它的含义。以下是考试中使用该语法的示例:
FOR $b IN //Brand
LET $cars :=
(FOR $c IN //Car
LET $cb := $c/@model => //Model/..
WHERE $cb/@name = $b/@name
RETURN $c)
LET $nr := COUNT($cars)
RETURN <Brand name={$b/@name}>{$nr}</Brand>
目标是计算每个品牌的所有汽车。
这是我的尝试:
FOR $b IN //Brand
LET $cars := (
FOR $c IN //Car
WHERE $c/@Model = $b/Model/@name //Might not work to match against all models this way?
RETURN ({c})
RETURN <Brand name={$b/@name}>COUNT($cars)</Brand>
这是 XML 文档:
<!DOCTYPE CarsNStars [
<!ELEMENT CarsNStars (Brand*, Car*)>
<!ELEMENT Brand (Model*)>
<!ELEMENT Model (Year+)>
<!ELEMENT Year (#EMPTY)>
<!ELEMENT Car (#EMPTY)>
<!ATTLIST Brand
name ID #REQUIRED
country CDATA #IMPLIED>
<!ATTLIST Model
name ID #REQUIRED>
<!ATTLIST Year
year CDATA #REQUIRED
horsePower CDATA #IMPLIED>
<!ATTLIST Car
regNr ID #REQUIRED
model IDREF #REQUIRED
miles CDATA #REQUIRED>
]>
编辑WHEN to WHERE,这显然是讲师的错字。