1

我正在尝试获取父母的社会保障。我尝试了此代码,但它返回空,但我知道该值不为空。

<xsl:call-template name="render-Employee">
    <xsl:with-param name="ssno" select="normalize-space(SocialSecurityNumber)"></xsl:with-param>
    <xsl:with-param name="firstName" select="normalize-space(FirstName)"></xsl:with-param>
    <xsl:with-param name="middleName" select="normalize-space(MiddleName)"></xsl:with-param>
    <xsl:with-param name="lastName" select="normalize-space(LastName)"></xsl:with-param>
    <xsl:with-param name="creationDate" select="ChangeDate"></xsl:with-param>
  </xsl:call-template>
  <xsl:for-each select="Dependents">
    <xsl:for-each select="Dependent">
      <xsl:call-template name="render-Dependent">
        <xsl:with-param name="recordType" select="'BN'" />
        <xsl:with-param name="employeeSsno" select="normalize-space(ancestor::Employee[1]/@SocialSecurityNumber)"/>

示例 xml

<Employee>
    <EntityKey>
      <EntitySetName>Employees</EntitySetName>
      <EntityContainerName>...</EntityContainerName>
      <EntityKeyValues>
        <EntityKeyMember>
          <Key>EmployeeId</Key>
          <Value xsi:type="xsd:int">873</Value>
        </EntityKeyMember>
        <EntityKeyMember>
          <Key>CompanyId</Key>
          <Value xsi:type="xsd:int">33</Value>
        </EntityKeyMember>
      </EntityKeyValues>
    </EntityKey>
    <Dependents>
      <Dependent>
        <EntityKey>
          ....
        </EntityKeyValues>
        </EntityKey>
        ...
        <SocialSecurityNumber>123456789</SocialSecurityNumber>
        ...
      </Dependent>
    </Dependents>
    <EmployeeId>873</EmployeeId>
    ...
    <SocialSecurityNumber>000000000</SocialSecurityNumber>
    ...
  </Employee>
4

2 回答 2

3

你的 XPath 表达式说

ancestor::Employee[1]/@SocialSecurityNumber

但在您的示例中,XMLSocialSecurityNumber是一个元素,而不是一个属性。

于 2012-10-02T16:46:06.720 回答
2

就目前而言,Employees SSN 是一个元素,而不是一个属性,因此您需要将 xpath 更改为

select="normalize-space(ancestor::Employee[1]/SocialSecurityNumber/text())"
于 2012-10-02T16:48:02.337 回答