Replace specific element value with new strings using conditions xslt 1.0

Techgeeks1

Want to replace orderLineStatus value with the conditions provided in xslt conditions(Assigned->assigned, Reserved->reserved etc).It works fine but all others nodes are not showing after transformation

**xml:**
<updateOrderLineStatusRequest
xmlns="http://www.abc1.com/schema/integration/helo/order"
xmlns:shipping="http://abc1.com/schema/integration/helo/shipping"
xmlns:message="http://abc1.com/schema/integration/message" message:timestamp="2021-01-25T10:13:13Z">
<orderLineStatusUpdate orderNumber="Test_001" line="3">
    <orderLineStatus>Assigned</orderLineStatus>
    <statusQuantity>1</statusQuantity>
    <leadTime unit="days">
        <shipping:min>4</shipping:min>
        <shipping:max>4</shipping:max>
    </leadTime>
</orderLineStatusUpdate>
</updateOrderLineStatusRequest>

xslt 1.0:

 <?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tst="http://www.abc1.com/schema/integration/helo/order"
xmlns:shipping="http://www.abc1.com/schema/integration/helo/shipping"
xmlns:message="http://www.abc1.com/schema/integration/message" message:timestamp="2021-01-25T10:13:13Z" >
<xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="no"/>
    <xsl:template match="tst:orderLineStatusUpdate ">
    <updateOrderLineStatusRequest >
        <xsl:choose>
            <xsl:when test="tst:orderLineStatus='Assigned'">
                <orderLineStatus>assigned</orderLineStatus>
            </xsl:when>
            <xsl:when test="tst:orderLineStatus='Reserved'">
                <orderLineStatus>reserved</orderLineStatus>
            </xsl:when>
            <xsl:otherwise>
                <orderLineStatus>reserved1</orderLineStatus>
            </xsl:otherwise>
        </xsl:choose>
    </updateOrderLineStatusRequest >
</xsl:template>
 </xsl:stylesheet>

The desired output is showing all the other nodes as well but my current output is showing only the orderLineStatus node

**Desired output:** 
  <updateOrderLineStatusRequest
 xmlns="http://www.abc1.com/schema/integration/helo/order"
 xmlns:shipping="http://abc1.com/schema/integration/helo/shipping"
  xmlns:message="http://abc1/schema/integration/message" message:timestamp="2021-01-25T10:13:13Z">
     <orderLineStatusUpdate orderNumber="Test_001" line="3">
      <orderLineStatus>assigned</orderLineStatus>
  <statusQuantity>1</statusQuantity>
     <leadTime unit="days">
       <shipping:min>4</shipping:min>
       <shipping:max>4</shipping:max>
   </leadTime>
  </orderLineStatusUpdate>
  </updateOrderLineStatusRequest>

 current output:
   <?xml version="1.0" encoding="UTF-8"?>
   <updateOrderLineStatusRequest xmlns:tst="http://www.abc1.com/schema/integration/helo/order" 
    xmlns:shipping="http://www.abc1.com/schema/integration/helo/shipping" 
      xmlns:message="http://www.abc1.com/schema/integration/message">
      <orderLineStatus>assigned</orderLineStatus>
    </updateOrderLineStatusRequest>
Siebe Jongebloed

Something like this(edited):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:tst="http://www.abc1.com/schema/integration/helo/order"
  xmlns:shipping="http://www.abc1.com/schema/integration/helo/shipping"
  xmlns:message="http://www.abc1.com/schema/integration/message" 
  exclude-result-prefixes="shipping message tst"
  >
  <xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="no"/>
  <xsl:template match="tst:orderLineStatusUpdate">
    <updateOrderLineStatusRequest xmlns="http://www.abc1.com/schema/integration/helo/order">
      <xsl:apply-templates select="@*|node()"/>
    </updateOrderLineStatusRequest>
  </xsl:template>
  
  <xsl:template match="tst:orderLineStatus">
    <xsl:copy>
      <xsl:choose>
        <xsl:when test=".='Assigned'">
          <xsl:text>assigned</xsl:text>
        </xsl:when>
        <xsl:when test=".='Reserved'">
          <xsl:text>reserved</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>reserved1</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:copy>
  </xsl:template>
    
  
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>

  </xsl:template>

</xsl:stylesheet>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Adding a new element based on a condition using XSLT at a Specific Location

How to loop through any XML and replace a specific Value using XSLT

Match and replace the name/value pair of an XML element using XSLT

XSLT - Add new element and value

replace value in xml using xslt

Replace 1 and 0 with strings in rendered table using vue

Replace strings in XML file using XSLT

Replace values in element in xml file using xslt

replace word using regex with specific conditions

How to replace NA in a dataframe for a specific value using the results of another column and taking into account conditions of another column?

Replace specific dom element with new content

XSLT count element value and create new element with the value

Finding a specific element in a xml file using xslt

How to insert new element in the xml using XSLT

XSLT replace an element that exists inside another element value

XSLT - Update value based on conditions from child of sibling element

XSLT - replace specific content of the text() node with a new node

Replace specific observations with new set of observations based on conditions in r

replace specific element of Dataframe to value of Series

Replace element with specific value to pandas dataframe

Replace a specific value from ALL attributes in an element

Powershell XML replace element with new value

Unable to group the element value using group by in XSLT

Replace last character in specific column with value 0

XSLT copy all and replace on conditions

XSLT replace char with an element

Add new element below existing element using xslt

How to insert new element using sibling element values with XSLT

Replace element in python 1D array if condition is met using the element value