2014-02-20 61 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>