473,387 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

xsl:value-of select and xsl:template match issue

2
Hi All,

A newbie to the forum and the world of XML/XSLT

I'm trying to create a XSLT script to convert from one XML format to another (cXML is the target format) for a system integration project.

I want to be able to map values in the source XML tags to the destination cXML tags as necessary but am stumbling on problems retrieving the right elements

Here comes the code...

Source XML to be converted

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <PublishMXPO_GOSOP xmlns="http://www.ibm.com/maximo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creationDateTime="2010-07-07T10:22:53+01:00" transLanguage="EN" baseLanguage="EN" messageID="1278494573441131060" maximoVersion="7 1 20090627-0754 V7115-149" event="0">
  4.   <MXPO_GOSOPSet>
  5.     <PO>
  6.       <BILLTO>BAKEWELL</BILLTO>
  7.       <BILLTOATTN>PMPRBOWNUSR</BILLTOATTN>
  8.     </PO>
  9.   </MXPO_GOSOPSet>
  10. </PublishMXPO_GOSOP>
  11.  
  12.  
XSL script

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4. version="1.0" xmlns:xalan="http://xml.apache.org/xslt">
  5.  
  6.     <xsl:output method="xml" version="1.0" doctype-system="http://xml.cxml.org/schemas/cXML/1.2.020/cXML.dtd" indent="yes"/>
  7.     <xsl:variable name="version">1.2.020</xsl:variable>
  8.  
  9.     <xsl:template match="/PublishMXPO_GOSOP">
  10.             <xsl:apply-templates select="PublishMXPO_GOSOP"/>
  11.     </xsl:template>
  12.  
  13.     <xsl:template match="*"> 
  14.         <xsl:variable name="messageID" select="@messageID"/>  
  15.         <xsl:variable name="timestamp" select="@creationDateTime"/> 
  16.         <xsl:variable name="version" select="$version"/> 
  17.  
  18.                 <cXML payloadID="{$messageID}" timestamp="{$timestamp}" version="{$version}" > 
  19.                     <BILLADDRESS><xsl:value-of select="*"/></BILLADDRESS>
  20.                     <BILLTOPERSON><xsl:value-of select="PublishMXPO_GOSOP/MXPO_GOSOPSet/PO/BILLTOATTN"/></BILLTOPERSON>
  21.                 </cXML>          
  22.     </xsl:template>    
  23. </xsl:stylesheet>
  24.  
  25.  
Current output XML

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.020/cXML.dtd">
  4. <cXML xmlns:xalan="http://xml.apache.org/xslt" version="1.2.020" timestamp="2010-07-07T10:22:53+01:00" payloadID="1278494573441131060">
  5. <BILLADDRESS>
  6.  
  7.       BAKEWELL
  8.       PMPRBOWNUSR
  9.  
  10.   </BILLADDRESS>
  11. <BILLTOPERSON/>
  12. </cXML>
  13.  
  14.  
I want to be able to split the two (and more) element values out into their respective target tags. Any clues on how to do this?

I've only managed to get anything returned from the source XML file by using xsl:value-of select="*". Using an XPATH expression like in <BILLTOATTN> does not work

Also, when I change the first template-match statement to / from /PublishMXPO_GOSOP I lose everything in the conversion except the xml version encoding header? I thought this should select all the nodes in the whole document?

Any advice on this is really appreciated

Cheers

Eugene
Jul 9 '10 #1
4 3475
Dormilich
8,658 Expert Mod 8TB
Also, when I change the first template-match statement to / from /PublishMXPO_GOSOP I lose everything in the conversion except the xml version encoding header? I thought this should select all the nodes in the whole document?
/ stands for the root document, // lets you select from everywhere. if you want to select all nodes, use *

what does the target XML should look like?
Jul 9 '10 #2
genox
2
Hi

Thanks for the quick response! :-)

Target XML should look like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.020/cXML.dtd">
  4. <cXML xmlns:xalan="http://xml.apache.org/xslt" version="1.2.020" timestamp="2010-07-07T10:22:53+01:00" payloadID="1278494573441131060">
  5.     <BILLADDRESS>BAKEWELL</BILLADDRESS>
  6.     <BILLTOPERSON>PMPRBOWNUSR<BILLTOPERSON/>
  7. </cXML>
  8.  
  9.  
Cheers
Jul 9 '10 #3
Dormilich
8,658 Expert Mod 8TB
I think you need to use the <xsl:copy> element, but I’m not an expert in copying.
Jul 9 '10 #4
jkmyoung
2,057 Expert 2GB
You're missing namespaces. Put xmlns:maximo="http://www.ibm.com/maximo" in your stylesheet node. So it should be instead:
<xsl:template match="maximo:PublishMXPO_GOSOP">

Also, you don't have to use variables; you can put the xpaths directly in the braces{} (unless you're using the variables for some sort of debugging purpose).
Jul 9 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Paul Mateer | last post by:
Hi, I have been running some queries against a table in a my database and have noted an odd (at least it seems odd to me) performance issue. The table has approximately 5 million rows and...
7
by: Lauren Quantrell | last post by:
Is there any speed/resource advantage/disadvantage in using Select Case x Case 1 Case 2 etc. many more cases... End Select VS.
1
by: Eddie | last post by:
I have a DataTable.Select() statement with a DateTime field that is being compared to a Date: Dim drCal as DataRow() = tblCal.Select("CalendarItemDate ='12/1/2003'", "CalendarItemDate",...
0
by: NTPT | last post by:
Hi. i have table like this: create table my_data ( cond_1 int8,cond_2 varchar(),cond_3 .... cond_n whatrver ,data text) This table represents a simple tree structure with known max level...
1
by: sp | last post by:
what is the advantage of using XSLTemplate over using the xsl file as XMLDOMDocument is it something related to performance? or functionality? i recently started using XSLT but i use the...
1
by: nx.nine | last post by:
hi, i've done some searching and haven't found a solution that worked, hopefully someone here can help. i apologize in advance for my dyslexic thought process. i have an xml file being...
3
by: Patrick | last post by:
Hi All, I'm new to all this and I'm back for more help. I am working with global variables. I'm trying to make my xls just display the data for the defined <moorname>. In my example I am using...
4
by: rossable | last post by:
The issue is that I need to place an a tag around an image in a .xslt file. Structurally and logically I don't see why this isn't working. <td class="bluecontent_head10d" colSpan="4"> <div...
3
markmcgookin
by: markmcgookin | last post by:
Hi, I have the following XML <AnswerList xmlns="http://tempuri.org/ALPS_Assessmentv1p1_RESCO_Schema.xsd"> <DateTimeLastSaved>12:12:12 1900</DateTimeLastSaved> <UserName>Bob</UserName>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.