Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 用于搜索表兄妹对的Xquery_Xml_Xslt_Xpath_Xquery - Fatal编程技术网

Xml 用于搜索表兄妹对的Xquery

Xml 用于搜索表兄妹对的Xquery,xml,xslt,xpath,xquery,Xml,Xslt,Xpath,Xquery,我有一个XSLT文档可以完成这项工作,但我想将其转换为xQuery! 我想搜索第一对表哥和第二对表哥。我想我只需要在xquery中转换xsl函数,但我对这一点完全陌生,有人能帮我吗 任何帮助都将不胜感激 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:my="my:my" exc

我有一个XSLT文档可以完成这项工作,但我想将其转换为xQuery! 我想搜索第一对表哥和第二对表哥。我想我只需要在xquery中转换xsl函数,但我对这一点完全陌生,有人能帮我吗 任何帮助都将不胜感激

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:my="my:my" exclude-result-prefixes="my xs">
 <xsl:output method="text"/>

 <xsl:key name="kChildren" match="Child"
  use="../HusbFath/*/@Ref"/>

 <xsl:key name="kChildren" match="Child"
  use="../WifeMoth/*/@Ref"/>

 <xsl:key name="kGrandParent" match="HusbFath | WifeMoth"
  use="my:GrandChildren(Link/@Ref)/*/@Ref"/>

 <xsl:variable name="vDoc" select="/"/>

 <xsl:template match="/*">
  First Cousins:
  <xsl:sequence select=
  "for $first in 1 to count(/*/FamilyRec/Child),
       $second in $first+1 to count(/*/FamilyRec/Child),
       $pers1 in (/*/FamilyRec/Child)[$first],
       $pers2 in (/*/FamilyRec/Child)[$second]
     return
       if(my:areFirststCousins($pers1, $pers2))
         then concat('[', $pers1/*/@Ref, ',', $pers2/*/@Ref, '] ')
         else ()
  "/>

  Second Cousins:
  <xsl:sequence select=
  "for $first in 1 to count(/*/FamilyRec/Child),
       $second in $first+1 to count(/*/FamilyRec/Child),
       $pers1 in (/*/FamilyRec/Child)[$first],
       $pers2 in (/*/FamilyRec/Child)[$second]
     return
       if(my:areSecondCousins($pers1, $pers2))
         then concat('[', $pers1/*/@Ref, ',', $pers2/*/@Ref, '] ')
         else ()
  "/>
 </xsl:template>

 <xsl:function name="my:GrandChildren">
  <xsl:param name="pRef" as="xs:string?"/>

   <xsl:sequence select=
   "key('kChildren',
        key('kChildren', $pRef, $vDoc)/Link/@Ref,
        $vDoc)
   "/>
 </xsl:function>


 <xsl:function name="my:areFirststCousins" as="xs:boolean">
  <xsl:param name="pPers1" as="element()"/>
  <xsl:param name="pPers2" as="element()"/>

  <xsl:sequence select=
  "key('kGrandParent', $pPers1/*/@Ref, $vDoc)[1]
  is
   key('kGrandParent', $pPers2/*/@Ref, $vDoc)[1]
  and
   not($pPers1/.. is $pPers2/..)
  "/>
 </xsl:function>

 <xsl:function name="my:areSecondCousins" as="xs:boolean">
  <xsl:param name="pPers1" as="element()"/>
  <xsl:param name="pPers2" as="element()"/>

  <xsl:sequence select=
  "my:areFirststCousins($pPers1/../(HusbFath|WifeMoth)[1],
                        $pPers2/../(HusbFath|WifeMoth)[1]
                       )
  "/>
 </xsl:function>
</xsl:stylesheet>

表亲:
表兄弟姐妹:
输入XML文件:

<GEDCOM>
    <HeaderRec>
        <FileCreation Date=""></FileCreation>
        <Submitter>
            <Link Target="" Ref="FM001"/>
        </Submitter>
    </HeaderRec>
    <FamilyRec Id="FM001">
        <HusbFath>
            <Link Target="IndividualRec" Ref="IN001"/>
        </HusbFath>
        <WifeMoth>
            <Link Target="IndividualRec" Ref="IN002"/>
        </WifeMoth>
        <Child>
            <Link Target="IndividualRec" Ref="IN004"/>
        </Child>
        <Child>
            <Link Target="IndividualRec" Ref="IN007"/>
        </Child>
    </FamilyRec>
    <FamilyRec Id="FM002">
        <HusbFath>
            <Link Target="IndividualRec" Ref="IN004"/>
        </HusbFath>
        <WifeMoth>
            <Link Target="IndividualRec" Ref="IN005"/>
        </WifeMoth>
        <Child>
            <Link Target="IndividualRec" Ref="IN006"/>
        </Child>
    </FamilyRec>
    <FamilyRec Id="FM003">
        <HusbFath>
            <Link Target="IndividualRec" Ref="IN007"/>
        </HusbFath>
        <WifeMoth>
            <Link Target="IndividualRec" Ref="IN008"/>
        </WifeMoth>
        <Child>
            <Link Target="IndividualRec" Ref="IN009"/>
        </Child>
    </FamilyRec>
    <IndividualRec Id="IN001">
        <IndivName>Fathers name</IndivName>
        <!-- This tag used for father of c1 or husband of w1 -->
        <Gender>Male</Gender>
        <AssocIndiv>
            <Link Target="" Ref="IN002"/>
            <Association>Wife</Association>
        </AssocIndiv>
    </IndividualRec>
    <IndividualRec Id="IN002">
        <!-- This tag used for mother of c1 or wife of h1 -->
        <IndivName>Mother s name</IndivName>
        <Gender>Male</Gender>
        <AssocIndiv>
            <Link Target="IndividualRec" Ref="IN001"/>
            <Association>Husband</Association>
        </AssocIndiv>
    </IndividualRec>
    <IndividualRec Id="IN003">
        <!-- This tag used for a child to h1 or w1 or grand son to gm1 or gf1 -->
        <IndivName>Child 1 name</IndivName>
        <Gender>Male</Gender>
        <AssocIndiv>
            <Link Target="IndividualRec" Ref="IN001"/>
            <Association>Father</Association>
        </AssocIndiv>
        <AssocIndiv>
            <Link Target="IndividualRec" Ref="IN002"/>
            <Association>Mother</Association>
        </AssocIndiv>
    </IndividualRec>
    <IndividualRec Id="IN005">
        <!-- This tag used for grand mother -->
        <IndivName>Grand mother's name</IndivName>
        <Gender>Male</Gender>
        <AssocIndiv>
            <Link Target="IndividualRec" Ref="IN004"/>
            <Association>Husband</Association>
        </AssocIndiv>
    </IndividualRec>
    <IndividualRec Id="IN004">
        <!-- This tag used for grand father -->
        <IndivName>Grand father's name</IndivName>
        <Gender>Male</Gender>
        <AssocIndiv>
            <Link Target="IndividualRec" Ref="IN005"/>
            <Association>Grand Father's Wife</Association>
        </AssocIndiv>
    </IndividualRec>
    <IndividualRec Id="IN006">
        <!-- This tag used for a child to h1 or w1 or grand son to gm1 or gf1 -->
        <IndivName>Child 1 name</IndivName>
        <Gender>Male</Gender>
        <AssocIndiv>
            <Link Target="IndividualRec" Ref="IN004"/>
            <Association>Father</Association>
        </AssocIndiv>
        <AssocIndiv>
            <Link Target="IndividualRec" Ref="IN005"/>
            <Association>Mother</Association>
        </AssocIndiv>
    </IndividualRec>
    <IndividualRec Id="IN007">
        <!-- This tag used for grand mother -->
        <IndivName>Grand mother's name</IndivName>
        <Gender>Female</Gender>
        <AssocIndiv>
            <Link Target="IndividualRec" Ref="IN008"/>
            <Association>Husband</Association>
        </AssocIndiv>
    </IndividualRec>
    <IndividualRec Id="IN008">
        <!-- This tag used for grand father -->
        <IndivName>Grand father's name</IndivName>
        <Gender>Male</Gender>
        <AssocIndiv>
            <Link Target="IndividualRec" Ref="IN007"/>
            <Association>Grand Father's Wife</Association>
        </AssocIndiv>
    </IndividualRec>
    <IndividualRec Id="IN009">
        <!-- This tag used for a child to h1 or w1 or grand son to gm1 or gf1 -->
        <IndivName>Child 1 name</IndivName>
        <Gender>Male</Gender>
        <AssocIndiv>
            <Link Target="IndividualRec" Ref="IN007"/>
            <Association>Father</Association>
        </AssocIndiv>
        <AssocIndiv>
            <Link Target="IndividualRec" Ref="IN008"/>
            <Association>Mother</Association>
        </AssocIndiv>
    </IndividualRec>
</GEDCOM>

父亲的名字
男性
妻子
母亲的名字
男性
丈夫
子1名称
男性
父亲
母亲
祖母的名字
男性
丈夫
祖父的名字
男性
外婆
子1名称
男性
父亲
母亲
祖母的名字
女性
丈夫
祖父的名字
男性
外婆
子1名称
男性
父亲
母亲

如果您只想将密钥函数转换为XQuery函数,请转到并准备好建议解决方案。

什么是配对?XSLT中没有提到它,是吗?您能提供一个输入XML(最好用占位符替换实名)吗?在XSL@Marcus RickertA下添加了XML文件。如果您有一些有用的东西,为什么要更改它?B) 三分之二的XSLT已经是XQuery。。。那么问题出在哪里?@Tomalak我想把XSLT中的函数改成XQuery函数,把键函数改成XQuery函数,请帮帮我,伙计!Thanks@user2217997你没有真正回答托马拉克的问题:你为什么要改变它?这一变化的好处是什么?我也看不出有什么理由这么做,因为您也可以从大多数XQuery处理器简单地调用xslt处理。我已经尝试更改了关键函数,因为在xslt中,我合并了这个函数,但我不知道如何在XQuery中执行,您能帮我吗。我也可以向你展示我迄今为止所做的一切。