Solved

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

Posted on 2014-04-09
9
660 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
  • 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

821 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