xslt 2.0中的select-of value

时间:2013-03-26 12:21:56

标签: xslt-2.0

我正在使用xslt 2.0。 我正在使用value-of select并获得因重复元素而返回的连接字符串。我尝试了previous-sibling和generate-id,并且都不会删除字符串的第二部分。我怎么能做到这一点?

输出

2 11 Kenneth Street 3755 Peachtree Road NE(要删除的第二个元素的粗体部分)

    <xsl:value-of select="wd:Personal_Data/wd:Contact_Data/wd:Address_Data/wd:Address_Line_Data[@wd:Type='ADDRESS_LINE_1']"/>

XML

    <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&amp;#xa;Barra de Tijuca&amp;#xa;Rio de Janeiro- RJ&amp;#xa;22621-252&amp;#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&amp;#xa;Atlanta, GA 30305&amp;#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>

1 个答案:

答案 0 :(得分:0)

如果您只想输出第一个选定的元素,请使用<xsl:value-of select="(wd:Personal_Data/wd:Contact_Data/wd:Address_Data/wd:Address_Line_Data[@wd:Type='ADDRESS_LINE_1'])[1]"/>

或者根据您显示的输入,我认为<xsl:value-of select="wd:Personal_Data/wd:Contact_Data/wd:Address_Data[1]/wd:Address_Line_Data[@wd:Type='ADDRESS_LINE_1']"/>也应该有用。

另请注意,您可以在样式表上使用version="1.0"和XSLT 2.0处理器来指示您正在将XSLT 1.0移至2.0但当前希望XSLT 1.0向后兼容处理(例如仅输出带有{的第一个选定节点{1}})。这样您就可以逐步调整代码。