XSLT用虚拟替换空节点



我的要求如下1)用%20代替空间2)替换/用%2F3)空的空元素为虚拟

样本输入:

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

所需的输出:

<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下尝试过,但找不到wat替换为假人例如

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

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中以匹配"空"元素

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

相关内容

  • 没有找到相关文章

最新更新