XSLT将空节点替换为伪节点

XSLT将空节点替换为伪节点,xslt,xslt-1.0,Xslt,Xslt 1.0,我的要求如下 1) 将空间替换为%20 2) 替换为%2F 3) 值为dummy的空元素 样本输入: <?xml version="1.0" encoding="UTF-8" ?> <process xmlns="http://xmlns.oracle.com/CCS/Project5/BPELProcess1"> <Sender>Sender 1</Sender> <TransactionId>Transact

我的要求如下 1) 将空间替换为%20 2) 替换为%2F 3) 值为dummy的空元素

样本输入:

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

发送者1
事务ID/2
交易类型5
状态6
70.73
备注8
全球结果9
决策类型10
由11决定
拉玛
所需输出:

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

发件人%201
事务ID%2F2
交易类型5
状态6
70.73
备注8
全球结果9
决策类型10
由11决定
笨蛋
拉玛
我已经尝试了XSLT,但找不到要虚拟的wat替换空节点 乙二醇

未转换为DUMMY
XSLT测试如下所示

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
  <xsl:apply-templates select="@*|node()"/>
</xsl:copy>
  </xsl:template>
  <xsl:template match="//text()">
    <xsl:call-template name="rep_SPLChar">
  <xsl:with-param name="text" select="."/>
    </xsl:call-template>
      </xsl:template>

  <xsl:template name="rep_SPLChar">
    <xsl:param name="text"/>
    <xsl:variable name="temp_space" select="'%20'"/>
    <xsl:variable name="temp_backslash" select="'%2F'"/>
    <xsl:if test="normalize-space($text) != ''">
      <xsl:choose>
        <xsl:when test="contains($text,' ')">
          <xsl:call-template name="rep_SPLChar">
            <xsl:with-param name="text"
           select="concat((concat(substring-before($text,'          '),$temp_space)),substring-after($text,' '))"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:choose>
        <xsl:when test="contains($text,'/')">
          <xsl:call-template name="rep_SPLChar">
            <xsl:with-param name="text"
                            select="concat((concat(substring-    before($text,'/'),$temp_backslash)),substring-after($text,'/'))"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$text"/>
        </xsl:otherwise>
      </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>
    </xsl:stylesheet>

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


笨蛋
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
  <xsl:apply-templates select="@*|node()"/>
</xsl:copy>
  </xsl:template>
  <xsl:template match="//text()">
    <xsl:call-template name="rep_SPLChar">
  <xsl:with-param name="text" select="."/>
    </xsl:call-template>
      </xsl:template>

  <xsl:template name="rep_SPLChar">
    <xsl:param name="text"/>
    <xsl:variable name="temp_space" select="'%20'"/>
    <xsl:variable name="temp_backslash" select="'%2F'"/>
    <xsl:if test="normalize-space($text) != ''">
      <xsl:choose>
        <xsl:when test="contains($text,' ')">
          <xsl:call-template name="rep_SPLChar">
            <xsl:with-param name="text"
           select="concat((concat(substring-before($text,'          '),$temp_space)),substring-after($text,' '))"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:choose>
        <xsl:when test="contains($text,'/')">
          <xsl:call-template name="rep_SPLChar">
            <xsl:with-param name="text"
                            select="concat((concat(substring-    before($text,'/'),$temp_backslash)),substring-after($text,'/'))"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$text"/>
        </xsl:otherwise>
      </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>
    </xsl:stylesheet>
<xsl:template match="*[not(*)][not(normalize-space())]">
  <xsl:copy>
    <xsl:apply-templates select="@*"/>
    <xsl:text>DUMMY</xsl:text>
  </xsl:copy>
</xsl:template>