我有以下XML
<bp>
<bp_id>319</bp_id>
<bp_name>HPP</bp_name>
<contact>
<id>239764182</id>
<first_name>abc</first_name>
<last_name>def</last_name>
<email>
<id>1234</id>
<email_address>xvxn@hddd.com</email_address>
<is_primary>true</is_primary>
</email>
<phone>
<id>222</id>
<phone_number>773890814350</phone_number>
<country_code>1</country_code>
<display_name>17733338908150</display_name>
<is_primary>true</is_primary>
<type_id>1201</type_id>
<type_code>Office</type_code>
</phone>
<bp_contact>
<is_admin_user>false</is_admin_user>
<is_company_officer>false</is_company_officer>
<shared_contact_type_id>3100</shared_contact_type_id>
<shared_contact_type_description>Direct Contact</shared_contact_type_description>
<role>
<role_id>8</role_id>
<role_name>something</role_name>
<responsibility>
<responsibility_id>3</responsibility_id>
<responsibility_name>this & thats</responsibility_name>
<is_primary_contact>false</is_primary_contact>
</responsibility>
<assignment>
<id>1507420</id>
<assignment_type_id>2002</assignment_type_id>
<abc_ven_number>4225506</abc_ven_number>
<department_id>97</department_id>
<is_primary_contact>false</is_primary_contact>
</assignment>
<assignment>
<id>552593</id>
<assignment_type_id>2002</assignment_type_id>
<abc_ven_number>1048993</abc_ven_number>
<department_id>97</department_id>
<is_primary_contact>false</is_primary_contact>
</assignment>
<assignment>
<id>1507391</id>
<assignment_type_id>2002</assignment_type_id>
<abc_ven_number>4225506</abc_ven_number>
<department_id>2</department_id>
<is_primary_contact>false</is_primary_contact>
</assignment>
<assignment>
<id>552551</id>
<assignment_type_id>2002</assignment_type_id>
<abc_ven_number>1048993</abc_ven_number>
<department_id>2</department_id>
<is_primary_contact>false</is_primary_contact>
</assignment>
</role>
<address>
<is_address_owner>true</is_address_owner>
<id>101227</id>
<line1>4501 W 47th</line1>
<city>Chicago</city>
<postal_code>60632</postal_code>
<country_code>US</country_code>
<country_name>UNITED STATES</country_name>
<subdivision_code>US-IL </subdivision_code>
<subdivision_name>Illinois</subdivision_name>
<validation_status>0</validation_status>
</address>
</bp_contact>
</contact>
<merch_planning_partnership_tier_id>9801</merch_planning_partnership_tier_id>
<merch_planning_partnership_tier_name>Basic Partner</merch_planning_partnership_tier_name>
</bp>
对于赋值下的abc_ven_number的多个值,我想要所有级别的abc_ven_number的所有值,它们应该用分号分隔。
4225506;1048993;4225506;1048993 -- like this.
以下是我的XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:ns="http://target.com/2012/03/01/canonical/BusinessPartner">
<xsl:strip-space elements="*" />
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">bp_name,bp_id
<xsl:for-each select="ns:bp_list/ns:bp">
<xsl:variable name="bp_name" select="normalize-space(ns:bp_name)" />
<xsl:value-of select="normalize-space(ns:contact/ns:bp_contact/ns:role/ns:assignment/ns:gms_vendor_number)"/>
<xsl:text>
</xsl:text>
</xsl:for-each></xsl:template>
</xsl:stylesheet>
这样,我只得到第一个值。我试过用“。”但我只想要abc_ven_number,而不是那个级别的其他值。
今天是我开始使用XSLT的第一天。
答案 0 :(得分:1)
这会在任意位置选择所有abc_ven_number
个元素,并将其文本与;
连接为分隔符:
<xsl:template match="/">
<xsl:for-each select="//abc_ven_number">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">
<xsl:text>;</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
答案 1 :(得分:1)
在XSLT 2中,您可以将xsl:value-of select与分隔符
一起使用<xsl:template match="/">
<xsl:value-of select="descendant::abc_ven_number" separator=";"/>
</xsl:template>
或者如果你想要不明确的值:
<xsl:template match="/">
<xsl:value-of select="distinct-values(descendant::abc_ven_number)" separator=";"/>
</xsl:template>