Solved

How to concatenate 2 fields into 1 field in xml with xsl or other

Posted on 2014-04-09
9
723 Views
Last Modified: 2014-04-10
Trying to merge the fields OrderField1 and JobType into the OrderField1 field.  
So if
OrderField1="PW" and jobType="Generic"

The end result would be OrderField1="PW-Generic"
OrderExport.xml
0
Comment
Question by:Knight905416
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 39989604
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    
    <xsl:template match="node()">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="/order">
        <xsl:copy>
            <xsl:apply-templates select="@*"/>
            <xsl:attribute name="OrderField1">
                <xsl:value-of select="@OrderField1"/>
                <xsl:text>-</xsl:text>
                <xsl:value-of select="job/@jobType"/>
            </xsl:attribute>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="@*">
        <xsl:copy-of select="."/>
    </xsl:template>
    
    
</xsl:stylesheet>

Open in new window

0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39989608
The only tricky thing in the template is the

           <xsl:apply-templates select="@*"/>
            <xsl:attribute name="OrderField1">

where you would have two attribute definitions of OrderField1 in a row,
but the second overwrites the first, so order is important
(assuming XSLT1)
0
 

Author Comment

by:Knight905416
ID: 39989669
Ok, thank you, looks like its moving in the right direction.  The only gap in my knowledge is how do I link the code with the xml.  Should there be a reference in the xsl?  Should the code be in the xml document?  Should the xsl file be in the same directory?  Is there a reference in the xml document pointing to the xsl document, etc?
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39989721
XSLT will transform XML into something else, could be XML as is the case here.

Making a reference to the XSL from within the XML only works if you need rendering in a browser, so you can't do that here

You need an XSLT processor, something that takes the XML, and the XSLT and returns the result XML

You need to tell me where you want to build that in, in a programming language? As a command line process? Basically one way or another you need to execute the XSLT against an XSLT processor
0
 

Author Comment

by:Knight905416
ID: 39989765
I guess we could use VB.Net or something.  I was hoping that XSLT could do this transformation.  I will attach my 2 files.  They produce nothing yet.
OrderExportTest1.xml
OrderExportTest1.xsl
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 39989838
well, your XSLT works perfectly on your source document

BUT as I said before, the xml stylesheet processing instruction is only usefull when you want to render in a browser

If you can use VB.net
http://www.codeproject.com/Questions/597678/ApplyplusXSLplustransformationplusonplusXMLplus-pl
google for vb.net + xslt, you will find a zillion of examples on how to do that
(I myself am not a VB developer)
0
 

Author Comment

by:Knight905416
ID: 39989898
I'm getting a completely blank browser with those files - tried in IE, Firefox and Chrome.
0
 
LVL 60

Assisted Solution

by:Geert Bormans
Geert Bormans earned 500 total points
ID: 39989955
Do you read what I write?

I told you twice allready that that won't work

I have tested the XSLT with a number of XSLT processors... the XSLT simply works

But if you use a xml-stylesheet instruction (which as I said only works for rendering the transformation result in a browser) you will see nothing. The reason is simple. Your target XML has a number of tags, but none are known html tags. Browsers ignore the elements they don't know, means that each browser will ignore the transformations result and show you a blank page. No surprise there

If you need the XML result as you put in your question, this implies an XML end result... well, then a browser can't help you
0
 

Author Closing Comment

by:Knight905416
ID: 39991890
Do you read what I write?  I love it.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
I starting with php 12 143
Reason for High TTFB 1 102
Is there a tool that can take a URL, scan the page and identify dead links? 9 125
Code Manager | Snippits 2 93
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question