XSLT/X-PATH EXPRESSION

2019-09-05 13:28发布

The Below is my input xml

<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>

My problem is only one or two fields i need to map in xslt other than that whatever is in the input i need in output.

Below is the code iam using in the xslt to copy input.

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

After that iam mapping one element which is not same in input and output by using the following x-path expression but iam not getting output.

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

By using the above copy code iam able to copy whole input as output but if iam trying to do map one element in xsl by using x-path expression as shown above which is not same in input and output iam not able to do so please help me on this.

标签: xml xslt
2条回答
干净又极端
2楼-- · 2019-09-05 13:48

Your question is not very clear, but based on my understanding i have tried this

<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>

Hope! this would meet ur requirement :)

查看更多
你好瞎i
3楼-- · 2019-09-05 13:55

Your XML has a default namespace xmlns="http://b2b.ibm.com/schema/IS_B2B_CDM/R2_2"

This means all nodes are under that namespace. You need to include this in your stylesheet in this case xmlns:ibm="http://b2b.ibm.com/schema/IS_B2B_CDM/R2_2". After that you can refer to a node using a prefix ibm:. exclude-result-prefixes="ibm" eliminates the prefix at the output.

The following stylesheet is probably what you need

<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>
查看更多
登录 后发表回答