XSLT用虚拟替换空节点

时间:2016-12-15 08:37:30

标签: xslt xslt-1.0

我的要求如下 1)用%20替换空格 2)更换/用%2F 3)空元素,其值为虚拟

示例输入:

rcb

必需输出:

<?xml version="1.0" encoding="UTF-8" ?>
  <process xmlns="http://xmlns.oracle.com/CCS/Project5/BPELProcess1">
     <Sender>Sender 1</Sender>
     <TransactionId>TransactionId/2</TransactionId>
     <TransactionType>TransactionType5</TransactionType>
     <Status>Status6</Status>
     <Limit>70.73</Limit>
     <Remarks>Remarks8</Remarks>
     <Result>GlobalResult9</Result>
     <Type>DecisionType10</Type>
     <DecidedBy>DecidedBy11</DecidedBy>
       <AddRequest1/>
     <AddRequest2>RAMA</AddRequest2>
     </process>

我在XSLT下面尝试了但是找不到一个wat替换Dummy的空节点 例如

<process xmlns="http://xmlns.oracle.com/CCS/Project5/BPELProcess1">
<Sender>Sender%201</Sender>
<TransactionId>TransactionId%2F2</TransactionId>
<TransactionType>TransactionType5</TransactionType>
<Status>Status6</Status>
<Limit>70.73</Limit>
<Remarks>Remarks8</Remarks>
<Result>GlobalResult9</Result>
<Type>DecisionType10</Type>
<DecidedBy>DecidedBy11</DecidedBy>
<AddRequest1>DUMMY</AddRequest1>
<AddRequest2>RAMA</AddRequest2>
</process>

尝试XSLT如下

<AddRequest1></AddRequest1> is not coverted to          <AddRequest1>DUMMY</AddRequest1>

1 个答案:

答案 0 :(得分:2)

尝试将此模板添加到XSLT以匹配“空”元素

<xsl:template match="*[not(*)][not(normalize-space())]">
  <xsl:copy>
    <xsl:apply-templates select="@*"/>
    <xsl:text>DUMMY</xsl:text>
  </xsl:copy>
</xsl:template>