1

My requirement is as below 1) Replace Space with %20 2) Replace / with %2F 3) empty elements with value as dummy

Sample Input:

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

Required Output:

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

I have tried below XSLT but could not find a wat replace empty node to Dummy eg

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

XSLT tried is as below

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

1 Answer 1

2

Try adding this template to your XSLT to match "empty" elements

<xsl:template match="*[not(*)][not(normalize-space())]">
  <xsl:copy>
    <xsl:apply-templates select="@*"/>
    <xsl:text>DUMMY</xsl:text>
  </xsl:copy>
</xsl:template>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.