Visit Our UNIX and Linux User Community


shell call xalan to transform xml with xslt, but can not find root node


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell call xalan to transform xml with xslt, but can not find root node
# 1  
Old 08-28-2009
shell call xalan to transform xml with xslt, but can not find root node

hi experts:

i am using xslt to transform xml in shell.

But can not find root node of source xml, if i remove the naming space definition in source xml, it works fine.

So our the question is how to let xslt know the naming space of srouce xml file?

Thanks for your kindly help in advanced.

a.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!--Sample XML file generated by XMLSpy v2009 (http://www.altova.com)-->

<FEED xsi:schemaLocation="http://www.thomsonreuters.com/xdb/FEED/iffm_cantors.xsd iffm_cantors.xsd"  xmlns="http://www.thomsonreuters.com/xdb/FEED/iffm_cantors.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">	
<MSG1 MESSAGE_TYPE="BONDS" MESSAGE_TYPE_NO="106">		
<INSTRUMENT>			
	<TP_DATE>2009-08-07T03:41:57.239014</TP_DATE>		
	<EMSN>1</EMSN>			
	<INST_TYPE>201</INST_TYPE>			
	<OPERATION>DR</OPERATION>				<SYMBOL>B00081828</SYMBOL>			
	<RIC>JP20010158=JSPN</RIC>			
	<DSPLY_NAME>CITY OF FUKUOKA </DSPLY_NAME>		
	<OFFCL_CODE>20010158</OFFCL_CODE>			
	<MATUR_DATE>2013-06-25T00:00:00</MATUR_DATE>		
	<CREATION_DATE>2008-06-09T05:50:11</CREATION_DATE>	
</INSTRUMENT>		
</MSG1>	
<MSG2 MESSAGE_TYPE="BONDS" MESSAGE_TYPE_NO="107">		
<INSTRUMENT>			
	<TP_DATE>2009-08-07T06:14:17.420433</TP_DATE>		
	<EMSN>1</EMSN>			
	<INST_TYPE>100</INST_TYPE>			
	<OPERATION>I </OPERATION>			
	<SYMBOL>ADB169A</SYMBOL>			
	<RIC>ADB169A=TS</RIC>			
	<DSPLY_NAME>ADB169A</DSPLY_NAME>
		
</INSTRUMENT>	
</MSG2>
</FEED>

a.xsl:
Code:
<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.thomsonreuters.com/xdb/FEED/iffm_cantors.xsd">

<xsl:output method="text"/>

<xsl:strip-space elements="FEED"/> 

<xsl:template match="FEED">
	
	<xsl:apply-templates/>

</xsl:template>

<xsl:template match="MSG1">
	<xsl:variable name="msg_type" select="@MESSAGE_TYPE"/>
	
	<xsl:variable name="msg_no" select="@MESSAGE_TYPE_NO"/>
	
	<xsl:for-each select="INSTRUMENT">
	
		<xsl:value-of select="$msg_type"/>|<xsl:value-of select="$msg_no"/>|<xsl:value-of select="TP_DATE"/>|<xsl:value-of select="EMSN"/>|<xsl:value-of select="INST_TYPE"/>|<xsl:value-of select="OPERATION"/>|<xsl:value-of select="SYMBOL"/>|<xsl:value-of select="RIC"/>|<xsl:value-of select="DSPLY_NAME"/>|<xsl:value-of select="OFFCL_CODE"/>|<xsl:value-of select="MATUR_DATE"/>|<xsl:value-of select="CREATION_DATE"/>
	<xsl:text>&#xA;</xsl:text>
	
	</xsl:for-each>

</xsl:template>

<xsl:template match="MSG2">
	
	<xsl:variable name="msg_type" select="@MESSAGE_TYPE"/>
	
	<xsl:variable name="msg_no" select="@MESSAGE_TYPE_NO"/>
	
	<xsl:for-each select="INSTRUMENT">
	
		<xsl:value-of select="$msg_type"/>|<xsl:value-of select="$msg_no"/>|<xsl:value-of select="RIC"/>|<xsl:value-of select="SYMBOL"/>|<xsl:value-of select="DSPLY_NAME"/>
	<xsl:if test="position()!=last()">
		<xsl:text>&#xA;</xsl:text>
	</xsl:if>
	
	</xsl:for-each>

</xsl:template>

</xsl:stylesheet>


Previous Thread | Next Thread
Test Your Knowledge in Computers #124
Difficulty: Easy
Generally speaking, Linux is only a Kernel, while Linux distributions are treated as an OS.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Looping through XML file on basis of a node

<?xml version="1.0" encoding="UTF-8"?> <Document> <FIToFICstmrCdtTrf> <GrpHdr> <MsgId>10001</MsgId> <NbOfTxs>1</NbOfTxs> <IntrBkSttlmDt>2015-05-06</IntrBkSttlmDt> <SttlmInf> <SttlmMtd>CLRG</SttlmMtd> </SttlmInf> <PmtTpInf> ... (2 Replies)
Discussion started by: harish2015
2 Replies

2. UNIX for Dummies Questions & Answers

Iterate/Loop Through XML Node List

I need to load an XML file and loop through a list of nodes in it to execute a shell script for each one using the attributes for each node as parameters for the script. Any ideas? Any help will be much appreciated. (1 Reply)
Discussion started by: bradlecat
1 Replies

3. Shell Programming and Scripting

Find Node and replace line(s) preceding in xml file

Hello, I have an xml file whose contacts are like below: <Node>Apple <B>Value1</B> <B>Value2</B> <B>Value3</B> </Node> <Node>Mango <B>Value1</B> <B>Value2</B> <B>Value3</B> </Node> <Node>Apple <B>Value1</B> <B>Value2</B> <B>Value3</B> </Node> <Node>Bannana (3 Replies)
Discussion started by: umarsatti
3 Replies

4. Shell Programming and Scripting

Need to find root element name of XML file

Given this XML: <?xml version="1.0"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> <cd> <title>Hide your heart</title> ... (2 Replies)
Discussion started by: ricksj
2 Replies

5. Shell Programming and Scripting

How to get the main node name in xml using perl?

Hi, I am having an conf file like this: <Main> <NODE> <NODENAME>FRUITS</NODENAME> <NAME>APPLE</NAME> <COLOUR>RED</COLOUR> <NODE> <IsWrapper/> <NODENAME>SEASONAL</NODENAME> <NODE> <NAME>MANGO</NAME> <COLOUR>GREEN</COLOUR> </NODE> </NODE>... (4 Replies)
Discussion started by: vanitham
4 Replies

6. Shell Programming and Scripting

How to get value from xml node using sed/perl/script?

hello, new to this forum. but i have a requirement to extract the value from multiple xml node and print out the values to new file with comma seperated. would like to know how this would be done using either sed/perl or some unix script. an example would be tremendous... sample input file:... (2 Replies)
Discussion started by: davidsouk
2 Replies

7. HP-UX

Need help for xslt transformation using Shell script

Hi I have one input xml file <param name="EXTR_COL" valueDesc="AUTHD_RFLL" value="rx.AUTHD_RFLL" /> There is a mapping parameters in Database. if EXTR_COL is present in input XML then it is mapped to fieldlist. so the o/p XML looks like <fieldlist> <datasource... (1 Reply)
Discussion started by: srinu19
1 Replies

8. Shell Programming and Scripting

Recursive call to find files and directories in Shell script from current path.

################################################################ Copy this script to your path from where you want to search for all the files and directories in subdirectories recursively. ################################################################# code starts here... (2 Replies)
Discussion started by: Ramit_Gupta
2 Replies

9. Shell Programming and Scripting

Shell script to find when user su'ed to root

Does anybody know how to make a shell script that finds all the times that any user su'ed to root and create a cron job sends that file output via e-mail to one user? Thanks!:confused: (1 Reply)
Discussion started by: jrvilino
1 Replies

10. AIX

Can't login root account due to can't find root shell

Hi, yesterday, I changed root's shell in /etc/passwd, cause a mistake then I can not log in root account (can't find correct shell). I attempted to log in single-mode, however, it prompted for single-mode's password then I type root's password but still can not log in. I'm using AIX 5L version 5.2... (2 Replies)
Discussion started by: neikel
2 Replies

Featured Tech Videos