XQUERY返回格式为<! - ELEMENT dynosaur($ dynosaurName)+ - >的结果

时间:2016-11-19 15:49:58

标签: xpath xquery flwor

我在XQUERY FLWOR文件中使用.xml表达式:

for $dynosaur in doc("document.xml")//species
 let $dynosaurName := $dynosaur/text()        // keeping the dynosaurName as a variable
return $dynosaur 

以上返回结果如下:

<species age="84">Velociraptor</species>

我需要格式化结果如下:

<!ELEMENT dynosaur (Velociraptor) +>

所以我正在尝试使用以下但不工作...

return <!ELEMENT dynosaur ({$dynosaurName}) +> //here i want that format but it return error

xml 文件:

<?xml version="1.0"?>
<dinosauria>
    <group>
        <name>saurishia</name>
        <subgroups>
            <group>
                <name>theropoda</name>
                <subgroups>
                    <group>
                        <name>carnosaurs</name>
                        <speciesList>
                            <species age="74">Dyptosaurus</species>
                            <species age="170">Megalosaurus</species>
                            <species age="67">Tyrannosaurus</species>
                        </speciesList>
                    </group>
                    <group>
                        <name>coelurosauria</name>
                        <speciesList>
                            <species age="84">Velociraptor</species>
                            <species age="110">Deinonychus</species>
                            <species age="228">Eoraptor</species>
                        </speciesList>
                    </group>
                </subgroups>
            </group>
            <group>
                <name>sauropodomorpha</name>
                <subgroups>
                    <group>
                        <name>sauropods</name>
                        <speciesList>
                            <species age="155">Brachiosaurus</species>
                            <species age="155">Camarasaurus</species>
                        </speciesList>
                    </group>
                </subgroups>
            </group>
        </subgroups>
    </group>
    <group>
        <name>ornithishia</name>
        <subgroups></subgroups>
    </group>
</dinosauria>

最后:

我无法找到任何方式来返回该类型的结果。我已经检查了很多考虑和本书的链接:http://www.datypic.com/books/xquery/chapter09.html

1 个答案:

答案 0 :(得分:1)

您可以尝试输出文字吗?

return concat("<!ELEMENT dynosaur (",$dynosaurName, ") +>")