2014-02-20 68 views
0

下面是我的輸入XML。在XSLT中選擇多個屬性

<ServiceIncident xmlns="http://b2b.ibm.com/schema/IS_B2B_CDM/R2_2"> 
    <ProviderID>INC0011731</ProviderID> 
    <ProviderPriority>4</ProviderPriority> 
    <WorkflowStatus>NEW</WorkflowStatus> 
    <ServiceProvider1> 
     <Person Role="AffectedUser"> 
      <ContactID>ITELLA_BRIDGE_USER</ContactID> 
      <FullName>Chad Whaley</FullName>  
     </Person> 
    </ServiceProvider1> 

下面是我的XSL

<xsl:template match="r2:Person/@Role">  
    <xsl:attribute name="Role">Owner</xsl:attribute> 
</xsl:template> 

<xsl:template match="r2:Person/@Role"> 
    <xsl:attribute name="Role">ReportedBy</xsl:attribute>   
</xsl:template> 

我的問題是我想在輸出這兩個領域的新人換舊人在input.Iam能夠輸出得到一個值,但IAM沒有得到其他值。

+2

這是一個錯誤有兩個模板精確匹配這樣同樣的事情。你能否在這個例子中顯示你實際期望的輸出,因爲這會讓你更清楚你想要達到的效果。謝謝! –

+2

您也在嘗試創建兩個具有相同名稱的屬性:如果允許,這將導致無效(格式不正確)的文檔。 –

回答

0

我放在一個空間屬性之間的分隔符:

<xsl:stylesheet version='1.0' xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:r2="http://b2b.ibm.com/schema/IS_B2B_CDM/R2_2" exclude-result-prefixes="r2"> 
    <xsl:output indent="yes"/> 

<xsl:strip-space elements="*"/> 

    <xsl:template match="node()|@*"> 
     <xsl:copy> 
      <xsl:apply-templates select="node()|@*"/> 
     </xsl:copy> 
    </xsl:template> 

    <xsl:template match="r2:Person"> 
     <xsl:copy> 
      <xsl:attribute name="Role">Owner ReportedBy</xsl:attribute> 
      <xsl:apply-templates/> 
     </xsl:copy> 
    </xsl:template> 

</xsl:stylesheet>