Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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 如何删除输出的父节点并仅显示没有父节点的子节点?_Xml_Xslt - Fatal编程技术网

Xml 如何删除输出的父节点并仅显示没有父节点的子节点?

Xml 如何删除输出的父节点并仅显示没有父节点的子节点?,xml,xslt,Xml,Xslt,我的xslt输出如下所示: <ext:PersonBirthDate> <ext:PersonBirthDate approximateDateIndicator="true" currentIndicator="false">1956-03-04</ext:PersonBirthDate> <ext:PersonBirthDate ext:approximateDateIndicator="false" ext:currentIndic

我的xslt输出如下所示:

<ext:PersonBirthDate>
    <ext:PersonBirthDate approximateDateIndicator="true" currentIndicator="false">1956-03-04</ext:PersonBirthDate>
    <ext:PersonBirthDate ext:approximateDateIndicator="false" ext:currentIndicator="false">1956-04-21</ext:PersonBirthDate>
    <ext:PersonBirthDate ext:approximateDateIndicator="false" ext:currentIndicator="true">1956-05-21</ext:PersonBirthDate>
</ext:PersonBirthDate>

1956-03-04
1956-04-21
1956-05-21
如您所见,父节点ext:PersonBirthDate有3个同名子节点。 如何删除输出中的父节点并仅显示3个子节点。

我希望我的输出如下所示:

<ext:PersonBirthDate approximateDateIndicator="true" currentIndicator="false">1956-03-04</ext:PersonBirthDate>
<ext:PersonBirthDate ext:approximateDateIndicator="false" ext:currentIndicator="false">1956-04-21</ext:PersonBirthDate>
<ext:PersonBirthDate ext:approximateDateIndicator="false" ext:currentIndicator="true">1956-05-21</ext:PersonBirthDate>
1956-03-04
1956-04-21
1956-05-21
XML文档

<Party ID="14474176" InternalPartyID="1612366618">
    <Gender Word="F ">Female</Gender>
    <ApproximateDOB>3/4/1956</ApproximateDOB>
    <DateOfBirth>04/21/1956</DateOfBirth>
    <DateOfBirth Current="true">05/21/1956</DateOfBirth>
</Party>

女性
3/4/1956
04/21/1956
05/21/1956
这是我的xslt代码,与原始代码略有不同

<!--Templates for DateOfBirth for the respondent-->
     <xsl:template match="DateOfBirth">
       <ext:PersonBirthDate>
          <xsl:attribute name="ext:approximateDateIndicator">false</xsl:attribute>
          <xsl:attribute name="ext:currentIndicator">false</xsl:attribute>
          <xsl:value-of select="mscef:formatDate(string(.))"/>
       </ext:PersonBirthDate>
     </xsl:template>

       <xsl:template match="DateOfBirth[@Current='true']">
         <ext:PersonBirthDate>
             <xsl:attribute name="ext:approximateDateIndicator">false</xsl:attribute>
             <xsl:attribute name="ext:currentIndicator">true</xsl:attribute>
             <xsl:value-of select="mscef:formatDate(string(.))"/>
         </ext:PersonBirthDate>
       </xsl:template>

<!--Templates for ApproximateDOB for the respondent-->
      <xsl:template match="ApproximateDOB">
          <ext:PersonBirthDate approximateDateIndicator="true" currentIndicator="{not(../DateOfBirth)}" >
          <xsl:value-of select="mscef:formatDate(string(.))"/>
        </ext:PersonBirthDate>
      </xsl:template>

<!--Respondent Template-->
    <xsl:template name="Respondent">
        <xsl:param name="pProtectionOrderID"/>
        <ext:Respondent>
<!--Guardian -->
    <xsl:for-each select="//CaseParty[(Connection[(@Word='GRD')])][1]">
        <xsl:for-each select="//Party[@InternalPartyID=current()/@InternalPartyID]">
            <xsl:call-template name="Guardian"/>
            <xsl:apply-templates select="ApproximateDOB|DateOfBirth"/>
        </xsl:for-each>
      </xsl:for-each>
   </ext:Respondent>
 </xsl:template>

假的
假的
假的
真的
或稍后:

<xsl:template match="ApproximateDOB">
    <ext:PersonBirthDate approximateDateIndicator="true" currentIndicator="{count(../ApproximateDOB)=1}">
        <xsl:value-of select="mscef:formatDate(string(.))"/>
    </ext:PersonBirthDate>
</xsl:template>

注意:IMHO您最好将所有三个DOB模板合并为一个(正如我相信您在上一个问题中已经向您提出的那样)


编辑: 只有当存在的唯一元素是ApproximateDOB时才是真的

啊。所以我们误解了这个要求。这可以通过改变以下方式实现:

<ext:PersonBirthDate approximateDateIndicator="true" currentIndicator="{count(../ApproximateDOB)=1}">

致:


然而,基于你的观点,我怀疑你的意思不是字面上的意思,因为当一方只有一个近似的B,但它也有一个性别时,这也会返回false。所以你可能想做:

<ext:PersonBirthDate approximateDateIndicator="true" currentIndicator="{not(../DateOfBirth)}">


相反,当并没有兄弟DateOfBirth元素时,它将返回true。

我已经将我的模板组合成一个。但是,当xml节点作为下面这样的其他出生日期时,输出不是我想要的
Party ID=“1”>3/4/1956 04/21/1956 05/21/1956
我将编辑问题并添加xml文档代码,以便您了解我的内容。我还将添加我希望输出外观的方式。@user3781064您没有足够的资源自己完成吗?希望您在这里学到了一些东西,而不仅仅是复制/粘贴。但是当近似指示符=“true”currentIndicator应该为false
1956-03-041956-04-21 1956-05-21
@user3781064时,如果(且仅当)当前父
参与方
元素正好有一个
近似对象
子元素,则得到currentIndicator=“true”—无论它可能有多少个其他子节点。--另外,请不要在评论中发布代码,这很难阅读。我想在近似的指示灯、Birthindicator的日期和CurrentIndicator前面加上ext:但我不知道该怎么做。我在这里发布了我想要的输出外观。
<ext:PersonBirthDate approximateDateIndicator="true" currentIndicator="{not(../DateOfBirth)}">