我是xslt的新手,我正在尝试用xlm文件在html中创建输出表。我坚持以下要求:如果存在,我需要拉出家庭地址,如果不存在,我需要使用工作地址。我正在处理代码以检查并将主Address_Line_1插入到我的表中。这是我正在使用的xml:
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<wd:Get_Workers_Response wd:version="v17" xmlns:wd="urn:com.workday/bsvc">
<wd:Request_Criteria>
<wd:Organization_Reference wd:Descriptor="MMM Money Market Mansion (Marcia Menos)">
<wd:ID wd:type="WID">f10da305867044b8a30c67671e4034c1</wd:ID>
<wd:ID wd:type="Organization_Reference_ID">SUPERVISORY_ORGANIZATION-1-219</wd:ID>
</wd:Organization_Reference>
</wd:Request_Criteria>
<wd:Response_Results>
<wd:Total_Results>5</wd:Total_Results>
<wd:Total_Pages>1</wd:Total_Pages>
<wd:Page_Results>5</wd:Page_Results>
<wd:Page>1</wd:Page>
</wd:Response_Results>
<wd:Response_Data>
<wd:Worker>
<wd:Worker_Reference wd:Descriptor="Gabriel Bezerra">
<wd:ID wd:type="WID">1efbe4be1e764a4d8dd205ee6550cafb</wd:ID>
<wd:ID wd:type="Employee_ID">21305</wd:ID>
</wd:Worker_Reference>
<wd:Worker_Data>
<wd:Worker_ID>21305</wd:Worker_ID>
<wd:User_ID>gbezerra</wd:User_ID>
<wd:Personal_Data>
<wd:Name_Data>
<wd:Legal_Name_Data>
<wd:Name_Detail_Data wd:Formatted_Name="Gabriel Bezerra" wd:Reporting_Name="Bezerra, Gabriel">
<wd:Country_Reference wd:Descriptor="Brazil">
<wd:ID wd:type="WID">1a29bb1357b240ab99a2fa755cc87c0e</wd:ID>
<wd:ID wd:type="ISO_3166-1_Alpha-2_Code">BR</wd:ID>
<wd:ID wd:type="ISO_3166-1_Alpha-3_Code">BRA</wd:ID>
<wd:ID wd:type="ISO_3166-1_Numeric-3_Code">76</wd:ID>
</wd:Country_Reference>
<wd:First_Name>Gabriel</wd:First_Name>
<wd:Last_Name>Bezerra</wd:Last_Name>
</wd:Name_Detail_Data>
</wd:Legal_Name_Data>
<wd:Preferred_Name_Data>
<wd:Name_Detail_Data wd:Formatted_Name="Gabriel Bezerra" wd:Reporting_Name="Bezerra, Gabriel">
<wd:Country_Reference wd:Descriptor="Brazil">
<wd:ID wd:type="WID">1a29bb1357b240ab99a2fa755cc87c0e</wd:ID>
<wd:ID wd:type="ISO_3166-1_Alpha-2_Code">BR</wd:ID>
<wd:ID wd:type="ISO_3166-1_Alpha-3_Code">BRA</wd:ID>
<wd:ID wd:type="ISO_3166-1_Numeric-3_Code">76</wd:ID>
</wd:Country_Reference>
<wd:First_Name>Gabriel</wd:First_Name>
<wd:Last_Name>Bezerra</wd:Last_Name>
</wd:Name_Detail_Data>
</wd:Preferred_Name_Data>
</wd:Name_Data>
<wd:Gender_Reference wd:Descriptor="Male">
<wd:ID wd:type="WID">d3afbf8074e549ffb070962128e1105a</wd:ID>
<wd:ID wd:type="Gender_Code">Male</wd:ID>
</wd:Gender_Reference>
<wd:Birth_Date>1980-08-13-07:00</wd:Birth_Date>
<wd:Marital_Status_Reference wd:Descriptor="Single (United States of America)">
<wd:ID wd:type="WID">0c855e50cb12452487de0caf7f262d4f</wd:ID>
<wd:ID wd:type="Marital_Status_ID">Single_USA</wd:ID>
</wd:Marital_Status_Reference>
<wd:Disability_Reference wd:Descriptor="Hearing Impairment (United States of America)">
<wd:ID wd:type="WID">a59abdaa91474e26a4fe3c55ec3775ef</wd:ID>
<wd:ID wd:type="Disability_ID">Hearing_Impairment_USA</wd:ID>
</wd:Disability_Reference>
<wd:Hispanic_or_Latino>0</wd:Hispanic_or_Latino>
<wd:Citizenship_Status_Reference wd:Descriptor="Citizen (United States of America)">
<wd:ID wd:type="WID">2ec46eb7edcc4d5aa97af54147204e0e</wd:ID>
<wd:ID wd:type="Citizenship_Status_Code">USA_Citizen</wd:ID>
</wd:Citizenship_Status_Reference>
<wd:Military_Service_Data>
<wd:Status_Reference wd:Descriptor="0 - Inactive (United States of America)">
<wd:ID wd:type="WID">dee05ff9af5341f08c5b0cc651d86f9b</wd:ID>
<wd:ID wd:type="Military_Status_ID">Inactive_USA</wd:ID>
</wd:Status_Reference>
<wd:Discharge_Date>2012-08-01-07:00</wd:Discharge_Date>
</wd:Military_Service_Data>
<wd:Identification_Data>
<wd:National_ID>
<wd:National_ID_Reference wd:Descriptor="001-33-3450 (USA-SSN)">
<wd:ID wd:type="WID">af5e69b72e2a404c8cd8c7383302f036</wd:ID>
</wd:National_ID_Reference>
<wd:National_ID_Data>
<wd:ID>001333450</wd:ID>
<wd:ID_Type_Reference wd:Descriptor="Social Security Number (SSN)">
<wd:ID wd:type="WID">93636994cfe84825a1daaa933cbba7e7</wd:ID>
<wd:ID wd:type="National_ID_Type_Code">USA-SSN</wd:ID>
</wd:ID_Type_Reference>
<wd:Country_Reference wd:Descriptor="United States of America">
<wd:ID wd:type="WID">bc33aa3152ec42d4995f4791a106ed09</wd:ID>
<wd:ID wd:type="ISO_3166-1_Alpha-2_Code">US</wd:ID>
<wd:ID wd:type="ISO_3166-1_Alpha-3_Code">USA</wd:ID>
<wd:ID wd:type="ISO_3166-1_Numeric-3_Code">840</wd:ID>
</wd:Country_Reference>
<wd:Verification_Date>2012-08-13-07:00</wd:Verification_Date>
</wd:National_ID_Data>
</wd:National_ID>
</wd:Identification_Data>
<wd:Contact_Data>
<wd:Address_Data wd:Effective_Date="2000-01-01-08:00" wd:Address_Format_Type="Extended" wd:Formatted_Address="Av Cmte Júlio Moura, 900&#xa;Barra de Tijuca&#xa;Rio de Janeiro- RJ&#xa;22621-252&#xa;Brazil" wd:Defaulted_Business_Site_Address="0">
<wd:Country_Reference wd:Descriptor="Brazil">
<wd:ID wd:type="WID">1a29bb1357b240ab99a2fa755cc87c0e</wd:ID>
<wd:ID wd:type="ISO_3166-1_Alpha-2_Code">BR</wd:ID>
<wd:ID wd:type="ISO_3166-1_Alpha-3_Code">BRA</wd:ID>
<wd:ID wd:type="ISO_3166-1_Numeric-3_Code">76</wd:ID>
</wd:Country_Reference>
<wd:Last_Modified>2009-06-06T20:07:49.246-07:00</wd:Last_Modified>
<wd:Address_Line_Data wd:Type="ADDRESS_LINE_1" wd:Descriptor="Street Name">Av Cmte Júlio Moura</wd:Address_Line_Data>
<wd:Address_Line_Data wd:Type="ADDRESS_LINE_3" wd:Descriptor="House Number">900</wd:Address_Line_Data>
<wd:Municipality>Rio de Janeiro</wd:Municipality>
<wd:Submunicipality_Data>Barra de Tijuca</wd:Submunicipality_Data>
<wd:Country_Region_Reference wd:Descriptor="Rio de Janeiro">
<wd:ID wd:type="WID">e88c3d7cdb2b4a8b8120ede0b16e2186</wd:ID>
<wd:ID wd:type="Country_Region_ID">BRA-RJ</wd:ID>
</wd:Country_Region_Reference>
<wd:Postal_Code>22621-252</wd:Postal_Code>
<wd:Usage_Data wd:Public="0">
<wd:Type_Data wd:Primary="1">
<wd:Type_Reference wd:Descriptor="Home">
<wd:ID wd:type="WID">836cf00ef5974ac08b786079866c946f</wd:ID>
<wd:ID wd:type="Communication_Usage_Type_ID">HOME</wd:ID>
</wd:Type_Reference>
</wd:Type_Data>
<wd:Use_For_Reference wd:Descriptor="Street Address">
<wd:ID wd:type="WID">f785430145674364a613cd56086942c4</wd:ID>
<wd:ID wd:type="Communication_Usage_Behavior_ID">STREET</wd:ID>
</wd:Use_For_Reference>
<wd:Use_For_Reference wd:Descriptor="Mailing">
<wd:ID wd:type="WID">9385649a0c4b4ddea7fb0d823c2f1bcd</wd:ID>
<wd:ID wd:type="Communication_Usage_Behavior_ID">MAILING</wd:ID>
</wd:Use_For_Reference>
</wd:Usage_Data>
</wd:Address_Data>
<wd:Address_Data wd:Effective_Date="2000-01-01-08:00" wd:Address_Format_Type="Basic" wd:Formatted_Address="3755 Peachtree Road NE&#xa;Atlanta, GA 30305&#xa;United States of America" wd:Defaulted_Business_Site_Address="1">
<wd:Country_Reference wd:Descriptor="United States of America">
<wd:ID wd:type="WID">bc33aa3152ec42d4995f4791a106ed09</wd:ID>
<wd:ID wd:type="ISO_3166-1_Alpha-2_Code">US</wd:ID>
<wd:ID wd:type="ISO_3166-1_Alpha-3_Code">USA</wd:ID>
<wd:ID wd:type="ISO_3166-1_Numeric-3_Code">840</wd:ID>
</wd:Country_Reference>
<wd:Last_Modified>2011-06-20T13:54:02.466-07:00</wd:Last_Modified>
<wd:Address_Line_Data wd:Type="ADDRESS_LINE_1" wd:Descriptor="Address Line 1">3755 Peachtree Road NE</wd:Address_Line_Data>
<wd:Municipality>Atlanta</wd:Municipality>
<wd:Country_Region_Reference wd:Descriptor="Georgia">
<wd:ID wd:type="WID">dec8eabbb13d45bdb159b8e25d896110</wd:ID>
<wd:ID wd:type="Country_Region_ID">USA-GA</wd:ID>
</wd:Country_Region_Reference>
<wd:Postal_Code>30305</wd:Postal_Code>
这是我遇到麻烦的xslt上的部分。它没有给我任何错误代码,但它什么都不做:
<xsl:for-each select="env:Envelope/env:Body/wd:Get_Workers_Response/wd:Response_Data/wd:Worker/wd:Worker_Data">
<tr>
<td><xsl:value-of select="wd:Worker_ID"/></td>
<td><xsl:value-of select= "wd:Personal_Data/wd:Name_Data/wd:Legal_Name_Data/wd:Name_Detail_Data/wd:Last_Name"/></td>
<td><xsl:value-of select= "wd:Personal_Data/wd:Name_Data/wd:Legal_Name_Data/wd:Name_Detail_Data/wd:First_Name"/></td>
<td><xsl:if test = "wd:Personal_Data/wd:Contact_Data/wd:Address_Data/wd:Address_Line_Data[@wd:Type = ADDRESS_LINE_1]"><xsl:value-of select="wd:Personal_Data/wd:Contact_Data/wd:Address_Data/wd:Address_Line_Data[@wd:Type = ADDRESS_LINE_1]"/></xsl:if></td>
前三列填充得很好,但是带有if语句的第四列什么也没做。根据收到的先前建议,我在xsl中的路径的开头消除了杂散“/”:if staatement,但它仍然没有做任何事情。有任何想法吗?我非常感谢您的帮助,并提前感谢,并感谢那些已经评论过的人!
答案 0 :(得分:0)
您显示的XSLT代码段的问题是在xpath表达式的开头使用了/
符号:
<xsl:if test = "/wd:Personal_Data/....
通过使用此正斜杠开始xpath表达式,这意味着它是一个绝对表达式,从顶层文档元素开始。你只需要一个相对表达式,相对于当前的 wd:Worker_Data 元素
<xsl:if test = "wd:Personal_Data/wd:Contact_Data/wd:Address_Data/wd:Address_Line_Data[@wd:Type = ADDRESS_LINE_1]">