2014-02-11 44 views
0

下面是我的XML輸入XSLT/X-路徑表達式

<ServiceIncident xmlns="http://b2b.ibm.com/schema/IS_B2B_CDM/R2_2"> 
<RequesterID/> 
<ProviderID>INC0011731</ProviderID> 
<ProviderPriority>4</ProviderPriority> 
<WorkflowStatus>NEW</WorkflowStatus> 
<Transaction> 
    <Acknowledge>1</Acknowledge> 
    <StatusCode>0</StatusCode> 
    <Comment>String</Comment> 
    <TransactionName>Problem_Submittal</TransactionName> 
    <TransactionType>2</TransactionType> 
    <TransactionDateTime>2012-10-19T16:05:56Z</TransactionDateTime> 
    <TransactionNumber>2012-10-19T16:05:56Z:1ae9b6a79901fc40fa75c64e1cdcc3b4</TransactionNumber> 
    <TransactionRouting>MX::ITELLASNINCBRDG</TransactionRouting> 
    <DataSource>ServiceNow</DataSource> 
    <DataTarget>NASPGR72</DataTarget> 
</Transaction> 

我的問題是隻有一個或兩個領域,我需要比其它XSLT無論是在輸入我需要在輸出映射。

以下是iam在xslt中使用的複製輸入的代碼。

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

其不是通過使用以下x路的表達,但不IAM獲得輸出在輸入和輸出相同的是IAM映射一個元件之後。

<TransactionRouting> 
    <xsl:text>Maximo</xsl:text> 
</TransactionRouting> 

通過使用上述複製代碼亞姆能夠整個輸入複製作爲輸出,但如果IAM試圖通過使用X路徑表達式做地圖中的xsl一種元素如上所示這是不是在輸入和輸出IAM相同不能這樣做,請幫助我。

+0

目前還不清楚你的意思是「在XSL中映射元素」。此外,請將您的問題的標題更改爲比「XSLT/XPath問題」更具體且更有意義的短語。謝謝! –

+0

你說的是「下面的XPath表達式」,但是你的問題中沒有顯示任何XPath表達式。你可以編輯問題來顯示_whole_ XSLT文件嗎? –

回答

0

你的XML有一個默認的命名空間xmlns="http://b2b.ibm.com/schema/IS_B2B_CDM/R2_2"

這意味着所有節點都是命名空間下。你需要在你的樣式表中包含這個xmlns:ibm="http://b2b.ibm.com/schema/IS_B2B_CDM/R2_2"。之後,您可以使用前綴ibm:來引用節點。 exclude-result-prefixes="ibm"消除了輸出處的前綴。

以下樣式表可能是你所需要的

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

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

    <!-- match element TransactionRouting --> 
    <xsl:template match="ibm:TransactionRouting"> 
     <xsl:copy> 
      <xsl:text>Maximo</xsl:text> 
     </xsl:copy> 
    </xsl:template> 

</xsl:stylesheet> 
0

你的問題不是很清楚,但根據我的理解,我已經嘗試過這種

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method='xml' indent='yes'/> 

    <xsl:template match='/'> 
     <xsl:apply-templates/> 
     <xsl:element name='TransactionRouting'>Maximo</xsl:element> 
    </xsl:template> 

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

</xsl:stylesheet> 

希望!這將符合你的要求:)

+0

考慮將' Maximo'更改爲' Maximo'。 –

+0

是不同的路線到相同的目的地 – 2014-02-11 11:10:50

+0

當然結果是相同的 - 但如果元素名稱是靜態地知道無論如何使用xsl:元素是不必要的複雜。 –