Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-04-09
9
Medium Priority
?
941 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 2000 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

877 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