我正在尝试获取父母的社会保障。我尝试了这段代码,但它返回空,但我知道该值不为空。
<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>
答案 0 :(得分:3)
您的XPath表达式
ancestor::Employee[1]/@SocialSecurityNumber
但在您的示例中,XML SocialSecurityNumber
是一个元素,而不是属性。
答案 1 :(得分:2)
就目前而言,Employees SSN是一个元素,而不是一个属性,所以你需要将xpath更改为
select="normalize-space(ancestor::Employee[1]/SocialSecurityNumber/text())"