0

I have created 2 dummy xmls with fake information however they are formatted exactly like the real versions, i'm wanting to take xml1 and format the information within it into looking like xml2.

XML1

<?xml version="1.0" encoding="UTF-8"?>
<CustomData type="C1QuoteToOrderB1">
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <soapenv:Body>
            <getOrderReturn>
                <CUST_NAME>Pizzas are us Ltd</CUST_NAME>
                <Detail>
                    <UNIT_PRICE>420.69</UNIT_PRICE>
                    <QUANTITY>38.0</QUANTITY>
                    <Input id="1020754265" name="CRUST_OPTION">
                        <Value id="STUFFED" name="STUFFED">
                            <label>Cheese Stuffed</label>
                        </Value>
                        <type>SN</type>
                        <label>Crust Option</label>
                    </Input>
                    <Input id="1838406646" name="TOP_TWO">
                        <Value id="TOPTWO" name="TOPTWO">
                            <label>Pineapples</label>
                        </Value>
                        <type>SN</type>
                        <label>Topping Two</label>
                    </Input>
                </Detail>
            </getOrderReturn>
        </soapenv:Body>
    </soapenv:Envelope>
</CustomData>

XML2

<?xml version="1.0" encoding="UTF-8"?>
<Specifications xmlns="http://schemas.driveworks.co.uk/interop/specification/1/0"> 
    <Specification Project="[Project Name]" Transition="[Name (Not Title) Of Transition]"> 
        <Input Name="Customer">Pizzas are us LTD</Input>
        <Input Name="Quantity">38.0</Input>
        <Input Name="Crust Option">Cheese Stuffed</Input>
        <Input Name="Topping Two">Pineapples</Input>
    </Specification>
</Specifications>

Below i am trying to pull through the label value however the colon stop my code from working, not sure how to navigate through this. If it's not obvious enough, i have little to no experience in xml and i am just trying to implement an idea i had.

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

    <xsl:value-of select="CustomData/soapenv:Envelope/soapenv:Body/getOrderResponse/getOrderReturn/Detail/Input/Value/label"/>

</xsl:template>
</xsl:stylesheet>

Is this possible to do using an xsl document and if so could i get some pointers, thanks.

  • I am sure it's possible - however (1) a single example does not provide sufficient information about the *rules* that need to be implemented by the transformation, and (2) you are basically asking for someone to write your code for you from scratch. If you run into a *specific* difficulty when writing your XSLT stylesheet, then you will have a legitimate question. – michael.hor257k May 21 '21 at 10:01
  • This is an easy task with xslt. I would start doing an https://www.data2type.de/en/xml-xslt-xslfo/xslt and/or buying this great book: https://www.amazon.nl/XSLT-2-0-XPath-Programmers-Reference/dp/0470192747. And then just start using it. If you then have any questions, google | and stackoverflow are your friends. – Siebe Jongebloed May 21 '21 at 10:05
  • @michael.hor257k thanks for the advice, i have added in one of the problems i've been having in trying to read in a value when the element includes a colon. I'm sorry if it seems that i am wanting others to do it all for me however i am very new to this and so am just trying to give as much info and a full scope of my goals with the hope of a few pointers. Google has been my friend. – Nathan Barrow May 21 '21 at 10:14
  • The answer to your specific question can be found here: https://stackoverflow.com/a/34762628/3016153 – michael.hor257k May 21 '21 at 10:23

1 Answers1

0

To get you started.

To use that prefix soapenv in XPath you have to declare it like this:

<xsl:stylesheet 
  version="1.0" 
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

But actually you don't need that namespace

Put this xsl:template in your xsl:

  <xsl:template match="getOrderReturn">
    <Specifications xmlns="http://schemas.driveworks.co.uk/interop/specification/1/0"> 
      <Specification Project="[Project Name]" Transition="[Name (Not Title) Of Transition]"> 
        <Input Name="Customer"><xsl:value-of select="CUST_NAME"/></Input>
        <Input Name="Quantity"><xsl:value-of select="Detail/QUANTITY"/></Input>
        <Input Name="Crust Option"><xsl:value-of select="Detail/Input[@name='CRUST_OPTION']/Value/Label"/></Input>
        <Input Name="Topping Two"><!-- Here the next xslt --></Input>
      </Specification>
    </Specifications>
  </xsl:template>
Siebe Jongebloed
  • 3,906
  • 2
  • 14
  • 19