Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-04-09
9
Medium Priority
?
878 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 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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.
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

721 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